I am interfacing this C code:
extern "C" void print_int(short a, int b, long c, long long d)
{
printf("%hi %i %li %lli", a, b, c, d);
}
with this Python code:
from ctypes import *
lib=cdll.LoadLibrary("./libtest.so")
lib.print_int(1,2,3,4)
Even if I don't cast the arguments in print_int
code, they are passed correctly and I get:
1 2 3 4
as expected. Why cannot ctypes do the same form floating-point numbers? The following snippet:
extern "C" void print_float(float a, double b, long double c)
{
printf("%f %lf %Lf", a, b, c);
}
would require an explicit cast from ctypes otherwise an exception is raised.
lib.print_float(c_float(1.0), c_double(2.0), c_longdouble(3.0))
I am working in Unix, compiling with the cdecl calling convention if that matters.