r/C_Programming • u/Kadabrium • 1h ago
Is there such a problem as "C++ style C"?
C++ programmers denounce "C-style C++" that uses primitive C features over newer C++ alternatives. Is the opposite a thing in C where excessive emulation of C++ features become a problem or an antipattern? Some possible examples off my head, no idea how common they actually are or whether they are considered bad; you are welcome to add more:
- Manual move and copy constructors on resource holders
- Manual vtables and inheritance
- Manual closure structs
- Macro-based template instantiation
- Opaque generic classes that use all of the above
6
Upvotes
4
u/nhermosilla14 1h ago
I while ago I saw some of this in a very old codebase. It was so bad it was funny. Some things looked like OOP stuff, but without any guarantee. It ended up being worse than both regular C and C++, because you couldn't even trust the code to behave as it said it did.
20
u/britaliope 1h ago
Oh god please no.
5
u/tstanisl 1h ago
I suggest being cautious with complex macros, they are nightmarish to debug and understand. Consider using STC (https://github.com/stclib/STC) style templates if you must as they much easier to work with. I strongly recommend using
container_ofpattern for inheritance. The rest is fine.2
u/HugoNikanor 1h ago
I've seen (and written) some such C code. My usual recommendation if you're starting to implement such features, is why you aren't just writing in C++ already.
1
u/ChickenSpaceProgram 1h ago
yeah all of the above are bad, with the exception of the container_of pattern, which can sorta be considered manual inheritance, except people mostly just use it for linked lists and stuff so it's not too bad
1
u/xvillifyx 1h ago
Seems like you should just use c++ instead
1
u/SpicerXD 1h ago
GLib/GObject without Vala, lol.
1
u/Zectbumo 49m ago
Fluent Interface in C - Look ma, no this! Tuesday, November 17, 2026 by Daniel Miller https://opensource.googleblog.com/2026/11/fluent-interface-in-c-look-ma-no-this.html?m=1
1
u/d1722825 32m ago
Huge (most?) part of the Linux kernel (especially the driver model and the VFS part) is written in OOP-style C, reimplementing many functionalities of the C++ (and other OOP) language in a worse* and more obscure* way.
A good example is the
container_ofmacro, that's basically used instead of class inheritance.They use
foo_init(struct foo*)as constructors, and function pointers in the struct as virtual functions. Theret = -EINVAL; goto ret4;error handling is very similar to destructors and (the terribly named) RAII.* Well, when the Linux kernel began C++ was very different from the today's C++ and compilers improved a lot since then, too, so it is not fair comparison.
1
u/cblacklabel 10m ago
Manual vtables are all over the kernel (file_operations etc) and nobody complains about those.
1
u/tastygames_official 5m ago
it seems like over half of all posts in the C groups here are people trying to do C++ style C. Is it a problem? I think it is. Can you do it? Sure. But why? It's like using a screwdriver as a hammer: sure you can do it, but just use a hammer. This works both ways.
Now I peronsally see no problem doing C-like C++, as maybe you're forced into using C++ for something because of necessary libraries and instead of rewriting them to be C-compliant or expose a C ABI, you can just write C-like C++. No problems. I think that happens all the time in the world of digital audio workstation (DAW) audio plugins (CLAP, VST etc). There are some C++ libraries/frameworks to help you get a plugin up and running real quick, and I even think you MUST use C++ for one of the formats as it expects a C++ ABI. But really most plugins don't really need OOP - they just need to read input, modify it, and generate some output. Sequences of numbers representing audio.
But if you're forced to use C for something and you really just can't handle not having a fat hierarchy of classes and overloading and all that stuff - then, well - you CAN do it, but it's like using a hammer to pull out a screw. It won't be pretty and it'll take way longer than just using a screwdriver.
But I don't know of any C programmers who want C++ functionality in C. They would just use C++ then. It's really a no-brainer.
-1
u/Prefer_Diet_Soda 1h ago •
Repeat after me:
Say no to C++.
Say no to:
hidden control flow because exceptions, destructors, and operator overloads run code behind my back.
Say no to:
hidden memory behavior because std::vector, std::string, smart pointers, and references obscure allocations, moves, and lifetimes.
Say no to:
type or compile-time gymnastics because templates, auto, and constexpr turn types and build errors into unreadable puzzles.
Say no to:
structural ceremony because classes, vtables, and :: namespaces add heavy abstractions and syntax noise where plain structs, functions, and naming conventions already work.