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

Show parent comment

1

u/flatfinger Oct 19 '26

Especially when adapting code written for one platform to make it usable on another, it would be helpful to say that if L is an lvalue of type struct widget, an expression like L->woozle+=3; would attempt to invoke a static inline function whose name was based on widget, woozle, and the "add-to" operator, if such a function exists, and otherwise attempt to invoke functions based upon widget, woozle, and the concepts of "read value" and "write value".

Unlike C++, a C implementation wouldn't "own" any of the bytes within a structure. If a programmer wants to implement virtual methods, the programmer would need to write a static inline function for the "virtual" member that would chain to the actual function via whatever means the programmer thinks best, using storage within the structure for that purpose exactly as specified in the source code.

1

u/LordRybec Oct 19 '26

Operator overloading is a two edged sword. If it is being used with types where it makes solid and obvious sense, it can be really good for making code more compact and readable. A lot of C++ programmers think it is slick to use operator overloading where it doesn't make obvious sense, and that creates two major problems. While still makes code compact it reduces readability substantially. A common problem with operator overloading, regardless of whether it makes sense or not, is that just looking at the code doesn't tell the reader what's actually happening. The operator implicitly calls a function, and unless you are already aware of that, the syntax doesn't indicate that it's doing that. That can be an absolutely massive problem for debugging. As people like to mention a lot, bugs often manifest sometime after the code where the bug actually is, so the crash or bad behavior is unlikely to happen within the overloading function. Tracking down a bug in a + operator for a particular type is always going to be a challenge, because + doesn't look like a function you need to look into, and which + function you need to look into isn't obvious from the like it is called in either.

Ideally a good implementation of operator overloading would include some syntax identifying that this is an overloaded operator, not a native one, and preferably also identifying what type that operator belongs to. But once you have all of that, the syntax is more complicated than just writing an add_widget_woozle(int x) function.

That said, platform based function overloading isn't a terrible idea. Currently we use #define filters, but if there was say, some set of function attributes, where you can specify the platform and OS, and then the compiler would ignore the function if it isn't for the target platform, that would be really handy. That would allow for making a series of functions with the same name but filtered for platform by the function attributes, where each function is for a different platform. Of course, each function would have to be fully exclusive of all others in terms of attributes used, to avoid a situation where there's a platform that two or more are valid for. That would, and should, cause a compile error for multiple function definitions. But such syntax would simplify the code and improve readability, by eliminating the need (at least at the function level) for long #ifdef blocks where it's easy to miss the #endif (or worse, where you have nested #ifdefs inside such that the #endifs are confusing).

---

Honestly, your idea isn't bad, but I'd generally hesitate to use operator overloading instead of a well named function, just to keep debugging easier. If my code is calling a function, it should look like it is calling a function. If you skipped the operator overloading and allowed for optionally specifying a platform/OS for each function though, function overloading for portability would be pretty awesome! (And let C++ add the same thing, that works with operator overloading, if it wants to.)

2

u/flatfinger Oct 19 '26

If operator overloading takes the form of fallback behavior when code tries to use an otherwise-undefined structure member, then something like p->foo += 3; could have three meanings:

  1. An access to member foo of p's type, if one exists.
  2. An invocation of a static inline function with a name formed in a particular way, that accepts p and 3 as arguments.
  3. An invocation of a static inline function that takes p as an argument and returns an int, followed by code that adds 3 to that int, and passes p and the result of that addition to another static inline function.

Allowing the latter meanings could facilitate easy adaptation of e.g. code that had relied upon a 32-bit integer structure member p->foo having been stored in big-endian order, to a little-endian platform. If nothing would form the address of p->foo and try to access it as a 32-bit integer via that pointer, then renaming foo to e.g. foo_little_endian, and having operations that read and write foo treated as invocations of an inline functions that combine an access to foo_little_endian with a byte swap, would avoid the need to rework source code that made use of p->foo in cases where performance wasn't too important.