What's The Difference Between Lp_* Pointers And *_p Pointers In Ctypes? (and Weird Interaction With Structs)
I'm having trouble understanding the difference between LP_* (e.g. LP_c_char) and *_p (e.g. c_char_p) pointers in Python ctypes. Is there documentation distinguishing them? The lit
Solution 1:
http://docs.python.org/library/ctypes.html#ctypes.c_char_p
Represents the C char * datatype when it points to a zero-terminated string. For a general character pointer that may also point to binary data, POINTER(c_char) must be used.
c_char_p
is mapped to Python's str
type because it's assuming you're referring to a string, which is generally the case when you're using char *
in C. LP_c_char
makes no such assumption.
Fundamental data types, when returned as foreign function call results, or, for example, by retrieving structure field members or array items, are transparently converted to native Python types. In other words, if a foreign function has a restype of c_char_p, you will always receive a Python string, not a c_char_p instance.
Post a Comment for "What's The Difference Between Lp_* Pointers And *_p Pointers In Ctypes? (and Weird Interaction With Structs)"