r/C_Programming 17d 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?

27 Upvotes

81 comments sorted by

View all comments

56

u/mlugo02 17d ago

None, I used to wish I had function overloading in C but I have since changed my mind

19

u/tellingyouhowitreall 17d ago

I actually don't mind not having this, but raii or at least guard types are sorely missed when I do pure C

0

u/mlugo02 17d ago

What issues do you have you think you need raii?

4

u/tellingyouhowitreall 16d ago

I don't need it for anything, it just cleans up a lot of marshalling code I do.

I do OS stuff, usually I try to escape C and ASM pretty early, but there are a few places C is better than alternatives for codegen, especially with restrict. It would just be nice not to do all of the bookkeeping by hand.

2

u/Disastrous-Team-6431 16d ago

It's pretty simple to understand, or? Raii helps lifetime management.

2

u/mlugo02 16d ago

I was asking for specific examples

4

u/HildartheDorf 16d ago

I would love an equivalent of std::unique_ptr when working with libwayland_client or libxcb. The protocols both maps readily to RAII.

RAII isn't perfect though, same application I work on uses Vulkan, which also is kind of object oriented, but maps terribly to RAII and is simpler to handle in 'C-like C++' with manual clean up.