r/C_Programming • • Oct 18 '26

C limitations

Hi all,

I am currently learning c++. Its okay. Not sexy but also not as bad as some say.

The reason I am learning c++ is that I have read that C has limitations as soon as a project gets more complicated. For example, if you make a scientific calculator with many features like graphs etc.

Trading engines/tools are also not recommended to programm in C.

Since I have not learned C and have only read from some old forum posts etc, I cannot confirm/deny these facts.

I am aware that "everything" is possible and that C++ comes with QoL improvements especially with Classes. But I assume that doesn't mean that someone has to use C only for kernel work. Embedded is also possible with C++ right?

I would appreciate your thoughts and opinions.

The goal of this post is to understand how and if C could fit me more with my goals and what real advantages or disadvantages C has.

51 Upvotes

114 comments sorted by

View all comments

0

u/olorochi Oct 19 '26

C++ has a lot of features, some of which cannot be reproduced exactly in C. However, these tend to come with pitfalls.

OOP is the classic example, and is quite easy to reproduce in C. The most challenging part is polymorphism, which can be achieved in C by manually creating vtables.

QoL features like RAII (automatic calls to constructors and destructors) tend not to be reproducible, but they don't affect the resulting binary, only the way the code is written. In my opinion, at least in the case of RAII, C is actually less error-prone than C++. Debugging a missing call to a custom deconstruction function or just free is far easier than fixing a badly written C++ deconstructor that fails in edge cases because it's copy constructor actually has move semantics (look into the history of std::auto_ptr). Another (far less controversial) example of this are templates. Whilst it isn't particularly difficult to reproduce basic template functionality in C, it does require a lot of copy-pasted code or particularly nasty macros.

Exceptions can be reproduced, though with difficulty, at a syntactic level, but C is not powerful enough to allow a resulting binary identical to what modern C++ compilers typically generate. Creating basic try, catch, throw and finally macros using the functionality from setjmp.h is not too difficult, but can easily cause memory leaks or dead file descriptors if the jump skips stack frames that contains ressources to deallocate. C++ compilers usually address this issue by embedding the information the program needs to find the relevant deconstructors of a stack frame in a dedicated section of the executable, which C compilers have no knowledge of. One solution would be to catch and throw again in every scope that must do clean-up, but littering code with catches is generally bad practice.

Another area where C falls short of C++ is reflection and compile time execution. The C++ standard library provides some functions that typically rely on compiler hooks for their implementation such as is_enum or is_class. As of C++26 there even is a proper reflection operator yielding compile time values: ^^. C++ programs can also branch and call some functions at compile time. Meanwhile C23's constexpr is just a way to create simple constants that could be used as an array size for example. These features are all just QoL, but allow for far more concise code in some cases.