3 ms·
RAII 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 ha
by stinos 12y ago
RAII
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.
- invernomut0 12y agoI remember something implemented as GCC extension (the cleanup variable attribute) but I never used it so I can't judge if it's really what are you searching for.
- guillaumec 12y agoGcc cleanup extension works very well for RAII, I used it extensively to write a simple profiler for a video game project (just add 'PROFILE' on top of a function to have it automatically profiled). The only problem is that this is not supported by MSVC.
- mitchty 12y agoIt is supported by clang though. Maybe you could use clang-cl to get it into msvc no?
- lelf 12y ago> Is there a clean way to implement something like this in C? __attribute__((cleanup(…)))