The problem here is that the function is defined as
double __cdecl add(int len, double array[]) { }
However, if you do not specify a return type for it, ctypes defaults to int . This is similar to declaring a function in C as
int __cdecl add(int len, double array[]);
Since the declaration and definition do not match, your code has undefined behavior, i.e.:
- A function is defined with a type that is incompatible with the type of (expression) that the expression denotes the function being called (6.5.2.2).
In this particular case, you work in an architecture where the values ββof integers and floating point values ββare returned to registers; however, the return values ββof int and double are stored in different registers. Now the register containing the return value of type int in this ABI contains N as the remaining one. The correct return value was contained in the floating point register, however, it was never used because ctypes expected to get an int .
Therefore, the correct correction must be performed
dll.add.restype = c_double
source share