Tag: compilers

C++ Calling Conventions

My advisor presented me with an interesting problem the other day. Calling some simple C++ free functions that took C++ objects by value using Python's ctypes produced strange results. We eventually narrowed the test case down to the following: 1#include <stdio.h> 2 3struct Simple { 4 int x,y,z; 5}; 6 7struct Fancy { 8 int x,y,z; 9 ~Fancy() { 10 printf("Destroying a Fancy\n"); 11 } 12}; 13 14extern "C" { 15 void printSimple(Simple s) { 16 fprintf(stderr, &qu…