Making "Classes" in C using Function Pointers and Pseudo Closures
02 Feb 2016
Who doesn’t want to write pseudo classes in C? A nice exercise is to do it once even if you plan to never do it again. Doing so you will have a greater appreciation for function pointers and what I am calling the pseudo closure idiom in C – passing a variable to emulate “private” data members. C doesn’t come with closures or almost anything for that matter. It is a very minimalist language which is, of course, one of its strengths and at times a weakness – like when a little abstraction could come in handy.
Written by Jim Lavrenz
Software engineer with a master's in software engineering. Follow me on
Twitter or Google+.