Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int myFunction(int num)
- {
- if (num == 0)
- // if number is 0, do not perform any operation.
- return 0;
- else
- // if number is power of 2, return 1 else return 0
- num & (num - 1) == 0 ? return 1 : return 0
- }
- cc -fPIC -shared -o dicmodule.so library.c
- import ctypes
- NUM = 16
- # dicmodule loaded to the python file
- # using fun.myFunction(),
- # C function can be accessed
- # but type of argument is the problem.
- fun = ctype.CDLL(dicmodule.so)
- # Now whenever argument
- # will be passed to the function
- # ctypes will check it.
- fun.myFunction.argtypes(ctypes.c_int)
- # now we can call this
- # function using instant (fun)
- # returnValue is the value
- # return by function written in C
- # code
- returnVale = fun.myFunction(NUM)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement