====================== '23 Mar 13 16:24 ====================== Written by ~leha2 from ctrl-c.club. Credit if shared. Thanks. ====================== Want to use classes in C? You can do it with structs and function pointers! In your headers: struct SomeClass { int propertyA; float propertyB; int (*modifyPropertyA)(struct SomeClass* self, int value); void (*free)(struct SomeClass* self); }; struct SomeClass* SomeClass_new(int valueA, float valueB); int SomeClass_modifyPropertyA(struct SomeClass* self, int value); void SomeClass_free(struct SomeClass* self); And in your sources: #include "SomeClass.h" struct SomeClass* SomeClass_new(int valueA, float valueB) { SomeClass* self = malloc(sizeof(*self)); /* You should check if allocation failed normally */ self->propertyA = valueA; self->propertyB = valueB; self->modifyPropertyA = &SomeClass_modifyPropertyA; self->free = &SomeClass_free; return self; } /* SomeClass modifyPropertyA function here */ void SomeClass_free(struct SomeClass* self) { free(self); /* If you have any other structures inside the class, you should free them too, otherwise you will have a memory leak. */ } And to call these functions inside your "class" struct, you do: struct SomeClass* class = SomeClass_new(1, 1.0f); (class->modifyPropertyA)(class, 2); /* Calling the function pointer */ (class->free)(class); You might not want to include class methods in contexts when you need to work with the least memory possible, as they also eat up your bytes.