copyninja
copyninja

Reputation: 1417

Python and C coupling

I tried loading C shared library .so in Python using ctypes.CDLL class (Linux). Here is the link to which tells what I did. As I see the documentation it says CDLL class assumes that function returns int types. I've a doubt here what if I need to return variable of type other than the int type from a function in C?. And to what extent we can use C functions in Python i mean what are the limits/restrictions on using C shared libraries and functions

Thanks in Advance

Upvotes: 4

Views: 244

Answers (1)

Matthew Flaschen
Matthew Flaschen

Reputation: 284786

By default, it assumes int, but you can set restype to any of the supported types to override that. E.g., from the docs:

strchr.restype = c_char_p

This means that strchr returns a pointer to a char, which corresponds to a Python string (or None, for a NULL pointer).

Upvotes: 4

Related Questions