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/LordRybec Oct 20 '26

And I don't want this misinformation out there, but you posted it anyway.

C++ is indeed less performant on average than C, often by a pretty wide margin. Argue all you want, but it doesn't make you right.

3

u/Vorrnth Oct 21 '26

Please stop posting this. It's absolutely wrong.

-1

u/LordRybec Oct 21 '26

Take your own advice.

2

u/Vorrnth Oct 22 '26

Why would be c++ any slower for the same features? Doesn't make any sense.

3

u/Kriemhilt Oct 20 '26

My whole career of high-performance C++ development in a shambles!

Citation please.

2

u/LordRybec Oct 20 '26

Citation please? On Reddit? I see at least 6 claims in your last post, with not even a hint of a bibliography. You sound like all of the Java devs of the last two three decades who claimed that Java was just as fast as C because it had JIT and who could not be convinced that JIT itself and the associated profiling cost extra cycles that were rarely refunded by the benefits of JIT. C++ devs have been claiming for ages that C++ is faster than C, and you know exactly what evidence I've seen? Contrived examples compared against deliberately non-optimal C code, just like the kind of examples provided by Java devs.

C++ devs claiming that C++ is just as fast, or sometimes even faster, than C have been around since the 1990s, demanding proof of counterclaims that C is in fact faster, but providing no practical, real life examples of C++ code using C++ features that this is actually true. And you have the nerve to demand proof from us?

If you actually wanted to know which is faster, you could have found the proof yourself with a simple Google search. There are hundreds, if not thousands, of examples online. Now, I'm sure you are going to claim that many of those examples are comparing apples to oranges, for example, cout takes approximately 60 times as long as printf, but cout is the default output call for C++ while printf is the default for C. If you are using printf in C++ to achieve the same speed, then you are essentially using C to cheat the numbers. This also applies to using structs instead of objects and so on. If you are foregoing C++ features to try to make C++ as fast as C, you aren't programming in C++. You are programming in C and compiling with the C++ compiler. Sure, I know, you "seriously disagree". I don't care if you disagree or not. If you cut out all of the C++ features that make C++ slow just to prove it can keep up with C, you are only proving that C is as fast as C, not that C++ can keep up with C.

Also, high performance C++ development? Bull crap. Your approach to this whole thing tells me you have no clue what high performance programming actually is. If you did, you would understand and agree with my claims intuitively. I believe you that you have some C++ experience, and maybe you've even had to do some optimizations to your programs (that you probably wouldn't have had to do with C) now and then. High performance? Not a chance. I'm not going to try to throw around my experience or credentials, because this is Reddit, and you can never know whether I'm telling the truth or not, but if you think what you were doing with C++ was high performance computing but don't understand enough hardware fundamentals to know that C++ can't keep up with C unless you are quite literally just writing C and compiling it with a C++ compiler, I can promise you what you were doing was not even remotely high performance anything.

2

u/Kriemhilt Oct 20 '26

No, all this tells me is that you don't know how to write performant C++. You're absolutely hung-up on the parts that nobody writing performant C++ uses for that specific reason, and you undervalue the features C doesn't have because you don't know how to use them.

Using C++ as essentially C with a better type system, and support for zero-cost abstractions that don't rely on macros, is an absolutely valid approach.

Completely agree on the Java stuff, but then I work in a field where unpredictable latency spikes are unacceptable, and trying to write Java while avoiding GCs is an exercise in masochism.

0

u/LordRybec Oct 20 '26

I know how to write performance C++. Write C.

I actually used to write mostly C++ and before that Java. My first modern language was Java. As a casual game dev (at the time), I quickly discovered Java couldn't keep up (it's faster now, but it's still slow compared to most other languages), so I learned C++. I then programmed mainly in Python and C++ for the next 15 years. Somewhere in there I went to college (I already had 10 years of experience with C++ and 20 years of programming experience in general by that time), where they also taught C++. I ultimately switched to C when I switched over to research, because I was only programmer on my team sufficiently experienced in C++ to optimize the massive programs we were writing for data analysis and certain kinds of simulation. The reason I switched to C is because I could almost always get a 2 to 4 times improvement in speed and reduce memory use by 10% to 20% just by rewriting in C. By the time I switched to C I already had significant experience converting crummy C++ to highly performant C++, and even that would typically get some benefit in both speed and memory by moving it over to C.

I do know how to use all of the features of C++. I went through education on that twice, once on my own and then a second time in college. Some I elected not to use up front, because they make debugging take substantially longer and harder and provide no benefits in terms of dev time, code readability, or performance. The rest all have performance costs. Most of them aren't obvious and cannot be solved or mitigated by the compiler, but they are sold as "zero cost" because the instructions themselves aren't more expensive. If you go out of your way to code differently, you can mitigate a lot of them, but the only way to avoid them entirely is to not use C++ features at all. What it sounds like to me is you are one of those C++ coders who mainly uses C features and avoid C++ features except where you know they aren't likely to have a cost that matters. It's not that hard in C++ write bottlenecks without C++ features to get massive performance gains, while writing code that either doesn't get called much or maybe is in a thread that doesn't need to go fast with C++ features. That's the same thing I did with game programming in C++, and it will get you pretty good results. I used techniques like this when I was in college to do things in C++ that even the professors didn't know you could get to run that fast (and then I got docked points on my grade for not using objects and expensive C++ types, because it was an OOP class I was supposed to do everything in OOP even if it didn't make sense and would destroy performance). The reality though is that if you can do highly performant code in C++, the same thing in C will almost always go faster and use less memory if you write performant C code. But, you and all of the others keep claiming that C++ can keep up, but the only examples I ever see are performant C++ code versus poorly written or at least not optimal C code.

Anyhow, I started programming games at a fairly young age, on systems with very limited CPU power and memory, and I learned to actually do time and memory profiling on my code to test what would perform best. I haven't done comprehensive time/memory profiling comparing C and C++, but I've done enough on bottleneck algorithms that actually matter, and C always wins. Note that I didn't say ties. It always wins, and often (though not always) by a large factor. Even empty programs in C and C++ aren't comparable. You say C++ makes a point of not "charging" for features you don't use, but this isn't true. Even empty C++ programs are doing more setup before calling main and using more background memory to track metadata that C doesn't track. The only way to avoid this is to compile without stdlib, but if you do that, you lose most of features that make C++ attractive over C.

And as far as having a "better type system", I've not found the C++ type system to be any better. C++ namespaces are nice, but swap a dot for an underscore, and you have the same thing in C. I don't find myself needing to use C macros for anything except defining global constants and platform filtering. I know some people think they need macros to do complex things, but I've found that you can generally do those things much more elegantly and cleanly without macros. I don't know how you think the C++ type system is better, but all I've found is that it requires a lot more mental space and effort to keep track of that I could be using for actually solving programming problems with instead. C has all of the types and type creation tools I need, and they are easier and faster to use and even easier to reason about than the horrific mess that is C++.

And yeah, I feel like modern Java traded fairly consistent poor performance for faster performance most of the time with massive lag spikes now and then. And I don't think it is just the GC. Java has had JIT since the mid 1990s, but over the years it has put more and more into the profiler and JIT, to try to improve speed. The problem is, profiling and compiling are inherently expensive. A light profiler and JIT can improve overall performance without noticeable lag spikes during profiling and compiling, but Java put a huge amount of effort and code into extremely deep profiling and extreme JIT optimization, and the result of that is lag spikes from the profiler and JIT. GC lag spikes are consistently worse in most applications, but the JIT and profiler aren't great either. They do increase average performance in most cases (though sometimes they end up consuming more resources than they save), but that comes at the cost of lag during deep profiling analysis and then the optimizing JIT following that. So modern Java is around twice as fast as old Java on average (on comparable hardware), but it's plagued with lag spikes that are a serious problem in games and high performance applications.