4 ms·
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 usefu
by torrance 12y ago
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?
- stinos 12y agoRAII 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(…)))
- thinkpad20 12y agoPerhaps you might be interested in Rust?
- rlpb 12y agoI really like talloc as a means of simplifying memory management. It's not, RAII, though.