Is it possible to implement RAII in pure C?
I assume it isn't possible in any sane way, but perhaps is it possible using some kind of dirty trick. Overloading the standard free
function comes to mind or perhaps overwriting the return address on the stack so that when the function returns, it calls some other function that somehow releases resources? Or maybe with some setjmp/longjmp trick?
This is of a purely academic interest and I have no intention of actually writing such unportable and crazy code but I'm wondering if that is at all possible.