Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42768

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

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;?

Upvotes: 0

Views: 218

Answers (2)

Mark Tolonen
Mark Tolonen

Reputation: 177971

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)

Upvotes: 2

Anycorn
Anycorn

Reputation: 51535

pointer = None

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

check 15.16.1.3. Calling functions

Upvotes: 2

Related Questions