I couldn't care less about trying to reimplement classes in C — structs and functions will do just fine thank you very much. What about something actually useful, like RAII to simplify memory management?
Please, yes. It happens I just spent the morning writing some C with files, views of those files etc, and I kept on whishing there was RAII, instead of having to build flow around the fact each of the operations might fail.
Is there a clean way to implement something like this in C?
I couldn't care less about trying to reimplement classes
indeed - the premise the OP starts with, i.e. 'here's the simplest class: BANG two subclasses' is also wrong. That is inheritance, not just 'the simplest class' as that wouldn't have anything to do with inheritcance.
__attribute__((cleanup(…)))