ctypes and C99 complex numbers

Thomas Heller theller at ctypes.org
Thu Aug 16 17:39:30 CEST 2007

Eugen Wintersberger schrieb:
> Hi there
>  I want to use ctypes in connection with C functions that use complex
> datatypes defined in the C99 standard. Does someone know a simple way
> how to implement this? Are there any plans to integrate the C99 complex
> data types in the ctypes module?

I have investigated the complex data types a bit and came to the conclusion
that libffi (which ctypes is based upon) would have to be extended to
support these complex types.  I have not looked into the newer libffi
sources to find out if this support already has been added, ctypes uses
an older version of libffi.

By experimenting I found out that on some systems (x86 linux and x86_64 linux)
I could 'emulate' the complex type by defining a structure:

class Complex(Structure):
   _fields_ = [("real", c_double), ("imag", c_double)]
   def _get(self):
   def _set(self, value):
   value = property(_get, _set)

but I'm afraid this is not really portable to other platforms.


More information about the Python-list mailing list