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

13

u/LordRybec Oct 19 '26

I don't find C++ easier to use than C. I find the supposed quality of life improvements to make the code harder to follow and especially more difficult to debug. When working with code written by someone else, I find that C code is generally written to a higher standard of quality and is easier to read than C++ code.

Now, this doesn't mean everyone has the same experience that I do. I know people who prefer C, some of who prefer C++, and some who don't like either. The reality is that "better" is somewhat subjective. I'd hate to do say, a scientific calculator in C++. Neither language is significantly better when it comes to string parsing. I see no benefits in using objects for such an application. I've actually written a graphing calculator in Python, and when I was much younger I wrote various types of graphing applications in QBasic for fun. The QBasic examples graphed specific functions and only took numerical inputs, but the Python one took full math expressions. Python has excellent text parsing capabilities built in. That part would be a lot more complex in C or C++. The supposed quality of life improvements in C++ wouldn't make any difference, aside from having to write a lot more code with very limited benefits if I wanted to use them. I don't know that I'd particularly want to do a graphing calculator in C, but I'd certainly prefer C over C++ for it.

Honestly, a lot of it is personal preference. C does have some distinct advantages, but they won't matter most of the time. Most of the features of C++ that people seem to like cost significant extra memory and processing time, and some can cost a lot of CPU time, causing the CPU to wait for cache/memory interactions. In general, C performs significantly better. But, unless you are writing code for embedded systems or ultra high performance applications, it won't matter. C++ objects maintain pointers to function tables, and those pointers cost extra memory. The typical object may use between 1% to 10% more memory than a similar struct due to the this. The way memory is organized within objects tends to cause cache memory to load entire objects even when only one or two member variables are being used, which increases cache misses, which costs a lot of CPU time waiting for memory to be loaded into cache. The use of function tables means that calling methods of objects costs at least two pointer lookups from memory, where calling a normal function that takes a struct would have the function call hard coded with no pointer lookups. Operator overloading makes function calls look like basic math operations, so you may not realize just looking at the code exactly how much it is actually doing. But again, if your program isn't already using a lot of memory and CPU time, these aren't going to make much difference. Modern CPUs are fast, modern systems have a lot of memory, and as long as you aren't being blatantly wasteful or completely careless, you program will work fine and won't even use enough resources to impact other processes on the same system. Maybe you find the C++ syntactic sugar additions to be more to your liking than I find to them to mine. If so, then maybe you'll like C++ better.

That said, if you are programming embedded systems, the increased costs of C++ can add up quite fast. You may not have to worry about the cache coherency issues (most embedded microcontrollers don't have cache in the first place), but having to do extra pointer lookups and maintaining function tables make a much bigger difference on a 8MHz to maybe 125MHz or so processor with anywhere from 500b to maybe 8MB of RAM. When working within resource constraints like that, the difference between C and C++ can be quite noticeable. It does still depend on what you are doing, but it's something you do need to consider. If nothing else, it can be the difference between managing the project on a 25¢ microcontroller and a microcontroller that costs a dollar or two. The price difference might not matter for a hobby project (though, what you happen to have lying around might matter), but for a professional project that you intend on selling copies of, it can be a huge difference. So sure, a lot of embedded stuff can be done in C++, but there are often good reasons not to even on systems where it can.

Anyhow, my personal preference is C, and I don't find the "quality of life" features of C++ (or even more recent C standards) to actually improve my quality of life, but your mileage may vary. If you want to learn C++, go ahead. It's unlikely to hurt. But go into with some introspection. C++ advocates will tell you that C++ features are a huge improvement. Don't blindly believe them. Pay attention to how they actually impact your workflow and judge them by the results you get out of them. In this field its easy to get sucked into the "newer is better" thing, but in my experience newer is often less stable, more experimental, and often different just for the sake of being different. There's a reason C is still being used even in new applications despite its advanced age. It's a very strong and powerful language, which has withstood the test of time extremely well. It's not perfect, but if it didn't have significant advantages, it wouldn't still be being used for new work almost constantly.

2

u/Kriemhilt Oct 19 '26

C++ objects maintain pointers to function tables

Nah, only if they use virtuals or RTTI.

People writing performant and/or embedded C++ just don't use those language features where it matters, and don't suffer any overhead.

Admittedly, having a list of language features that you have to learn, and then also learn when & why not to use, is a lot of extra stuff for C++ learners.

Preferring C is still perfectly reasonable, but there's room to use C++ as "just" C with better type safety, type-safe generics, compile-time metaprogramming, and possibly newer features like reflection and stackless coroutines.

The more Java-like object-oriented C++ that you're arguing against hasn't been idiomatic since maybe 2011, even though it's still widespread in enterprise settings.

2

u/LordRybec Oct 19 '26

Sure, let's use a language with a bunch of advanced features but not use them, because of performance and memory issues, instead of using a language that is well suited to the application.

I'm not saying C++ doesn't have places where it works and sometimes even well, but if your application requires cutting out a significant portion of the language, you are probably using the wrong tool for the job.

And yes, part of the problem with C++ is that the number of features it has make it a lot harder to learn (and a lot harder to remember all of them even once you have learned them). Yeah, you don't need to know them all to program well in C++, but again, if you aren't going to learn and take advantage of the features, maybe you'd be more comfortable with a different tool.

As far as things like type safety, my specific use cases would be hindered by increased type safety. Type manipulation stuff is often quite necessary in embedded systems and low level programming in general, so stricter type safety means more unnecessary hoops to jump through. That said, increased type safety when you don't need heavy type manipulation can be really nice. Haskell has incredibly strong type safety, which often means that if you can get your program to compile, it has very few or maybe even no bugs. (Which is a bit disconcerting, to be honest.)

2

u/Kriemhilt Oct 19 '26

if your application requires cutting out a significant portion of the language

Strongly disagree on this. C++ is a big multi-paradigm language, and it's completely normal to pick a suitable subset for a particular region of code.

Obviously I do agree though that being big, and supporting multiple paradigms, makes it a lot more to learn.

2

u/LordRybec Oct 19 '26

This is the fallacy of the "do everything" language that drove Java into common use. "My language is a big language that can do all of the things really well" is never true. That's called bloat, and it's part of the reason C++ is substantially less performant than C unless you avoid using most of its non-C-like features.

I understand that it's normal to pick a suitable subset of code/syntax from a massively bloated language. This is part of the reason most modern applications are garbage under the hood. You assume that normal means good, but this is not always the case.

The reality is, the more generalist a high level language (or library, or framework, or platform...) gets, the worse it gets at doing any particular thing. This is because it has to support a huge amount of use cases that any given application only uses a small handful of, and that generalization adds a lot of overhead. This is why cout is so much more expensive than a write system call. (And even printf is moderately more expensive.) The write system call is perfectly well suited to printing out any string you give it, but cout wants to handle type conversion to text for a massive number of different things. write is very narrow and leaves things like conversion to the user. cout is extremely generalist and tries to do everything, the consequence of which is that it can't do anything with good performance or memory usage.

This extends to C++ in general. C is very narrow and leaves the vast majority of things up to the programmer, providing only a handful of basic tools. C++ tries to gives you the kitchen sink, but as a result it's not ideal for any application. (And Java tries to give you the moon on top of that.) If you are only using a small subset of C++ specific features, you are better off using a less generalist language that doesn't have the features you aren't using, because tossing a bunch of the generalist stuff will save you RAM, CPU time, and other resources (often including development time). Maybe you don't care about those things as much as the few C++ features you want to use, but the point is that there are significant, objective benefits to choosing a better suited language if your application requires cutting out a significant portion of the language you are using. Personal preference is purely subjective and does not magically make the objective benefits go away, no matter how strongly you disagree. Anyone can choose to use a poorly suited language for their application, but that doesn't make it wise or good to do so, even if it is normal to do so.

3

u/Kriemhilt Oct 20 '26

I strongly disagree with pretty much all of this. I doubt I'll persuade you, but I don't really want this sort of reactionary misinformation floating around unchallenged.

it's part of the reason C++ is substantially less performant than C unless you avoid using most of its non-C-like features.

  • C++ isn't substantially less performant than C, full stop.
  • It does add some features that have more overhead because they're providing facilities C doesn't have at all.
  • Nobody is forcing you to use those features, and it's perfectly normal not to.
  • The non-C-like features that are completely free include for example:

    • templates (which are much better macros for many of the situations where you use the preprocessor in C, for want of anything better)
    • type safety, which has no runtime overhead even where you do need the reinterpret_cast escape hatch, and has no downside at all except for verbosity where you're doing something unusual (or non-portable, or inadvisable)

that generalization adds a lot of overhead

entirely false, the entirely philosophy of C++ is that you don't pay for what you don't use.

This is why cout is so much more expensive than a write system call

No, it's because it's doing a lot more stuff. The design is now consider old & clunky anyway, and std::print was added for a reason, but it's not a fair comparison. If you don't need all that "stuff" (customizable typesafe formatting, facets, per-stream locales, etc. etc.) then just don't use it. There's no overhead for not using something, and it is again perfectly normal to just not use things you don't need.

write is very narrow and leaves things like conversion to the user

Scattering error-prone manual string formatting and buffer management through your code is empirically not an improvement, except in the very niche cases where that's your main focus or a huge bottleneck. Write being lean isn't an improvement if you still need to call snprintf to generate the buffer to write. C isn't "bloated" for having a redundant printf function in addition to snprintf+write, and C++ isn't bloated for adding a safer, more correct but slower, iostreams either.

C++ tries to gives you the kitchen sink, but as a result it's not ideal for any application.

C++ is closer to the "batteries included" philosophy that the standard library should provide enough tools, to a good enough standard, to at least get started.

std::unordered_map will give you a fairly reasonable hashmap for literally no effort, and if that implementation turns out to be a bad fit, switching to the boost or absl or folly implementations just requires a typedef.

C++ isn't limiting you at all by giving a sane default, and C isn't saving you time or overhead by giving you literally nothing to get started with.

significant, objective benefits to choosing a better suited language if your application requires cutting out a significant portion of the language you are using

Choosing what part of a language you're using isn't "cutting out" anything. You're still writing C even if you never use bitwise-XOR in a particular program. Nobody will accuse you of "cutting out" parts of the language, or suggest using a different language that doesn't have bitwise-XOR in the first place because "it's a better fit for your problem". Nobody will do this because the argument is insane on its face.

I understand this might be hard to believe if you're used to a single-paradigm language with a single reasonable way of doing things, and it's totally reasonable than not everyone likes languages that support lots of different styles, use cases, features etc. But deciding what language features or libraries support a given program is normal even in C. It's just less obvious because there's less scope to choose.

And the very obvious advantage to having a single multi-paradigm language is that I can choose different subsets for different parts of a program and still have it all interoperate without needing FFI bindings or multiple compilers. If I want my core logic to be purely functional, my support libraries to be templated, and the configuration library whose performance I don't care about at all, to use OOP and exceptions, there's no problem at all.

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.

→ More replies