/******** * foo.c * * An example of a small python class in C * The corresponding python is in ./foo.py. * * $ gcc foo.py -o foo * $ ./foo * <foo bar=10 at 0x7fb861405af0> * * Jim Mahoney | cs.bennington.college | MIT License | March 2021 ******/ #include <stdio.h> #include <stdlib.h> // ----- 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("<foo bar=%d at %p> \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 }