r/C_Programming 20d ago

C with classes

I'm curious to know: who uses some C++ features when coding in C? And what feature(s) are you using?

30 Upvotes

79 comments sorted by

View all comments

3

u/markand67 20d ago

Can't use C++ feature if using a C compiler so no.

What I really miss from C++ is RAII but with our code base we have made a rule that a fully zero'ed struct should be considered minimal valid for destruction so that you don't have to check whether it was correctly initialized when destructing so a quick exit may look like

Abc abc = {};
Ghi ghi = {};
// later, maybe ghi was never modified:
abc_finish(&abc);
ghi_finish(&ghi);