Why if i have this simple code
void voidFunct() {
printf("voidFunct called!!!\n");
}
I compile it as a dynamic library with
gcc -c LSB.c -o LSB.o
gcc -shared -Wl -o libLSB.so.1 LSB.o
And i call function from a python interpreter, using ctypes
>>> from ctypes import *
>>> dll = CDLL("./libLSB.so.1")
>>> return = dll.voidFunct()
voidFunct called!!!
>>> print return
17
why the value returned from a void method is 17 and not None or similar? Thank you.
From the docs:
In short, you defined voidFunct() as a functioning returning
int, not void, and Python expects it to return anint(which it gets, somehow, anyway – it’s just happen to be a random value).What you should probably do, is to explicitly state a return value type of
None.