/******** * foo.c * * An example of a small python class in C * The corresponding python is in ./foo.py. * * $ gcc foo.py -o foo * $ ./foo * * * Jim Mahoney | cs.bennington.college | MIT License | March 2021 ******/ #include #include // ----- all this is the Foo class in python --------- typedef struct _foo *Foo; // a Foo is a pointer to a (struct _foo) struct _foo { int bar; }; Foo newFoo(int bar){ Foo self = malloc(sizeof(struct _foo)); self->bar = bar; return self; } void printFoo(Foo self){ // similar to the __str__ method ; how should I print this printf(" \n", self->bar, self); } // -------------------------------- int main() { Foo foo = newFoo(10); // python : foo = Foo(10) printFoo(foo); // python : print(foo) return 0; // send "success" to the operating system }