开发者

Python interfacing with C library - How to have a null c pointer

开发者 https://www.devze.com 2023-02-11 04:00 出处:网络
I have the following old c code. const char *c[3]; c[0] = \"ABC\"; c[1] = \"EFG\"; c[2] = 0; c_function(c);

I have the following old c code.

const char *c[3];
c[0] = "ABC";
c[1] = "EFG";
c[2] = 0;
c_function(c);

Now, I need to use Python to call old c function. I have the following code.

c_names = (c_char_p * 3)()
c_names[0] = "ABC";
c_names[1] = "EFG";
// c[2]开发者_运维技巧 = 0??
libc = CDLL("c_library.dll")
libc.c_function(c_names)

May I know what is the Python equivalent for c[2] = 0;?


None and 0 both work:

>>> import ctypes
>>> x=ctypes.c_char_p(0)
>>> x
c_char_p(None)
>>> x=ctypes.c_char_p(None)
>>> x
c_char_p(None)


pointer = None

http://docs.python.org/library/ctypes.html

check 15.16.1.3. Calling functions

0

精彩评论

暂无评论...
验证码 换一张
取 消