Calling C/C++ with ctypes
The ctypes
library makes it easily possible to call functions from C libraries, but you do need to be careful with memory access and data types. Python is generally very lenient in memory allocation and type-casting; C is, most definitely, not that forgiving.
Platform-specific libraries
Even though all platforms will have a standard C library available somewhere, the location and the method of calling it differs per platform. For the purpose of having a simple environment that is easily accessible to most people, I will assume the use of an Ubuntu (virtual) machine. If you don’t have a native Ubuntu machine available, you can easily run it through VirtualBox on Windows, Linux, and OS X.
Since you will often want to run examples on your native system instead, we will first show the basics of loading printf
from the standard C library.