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

97

u/Humble_Anxiety_9534 Oct 19 '26 • Bravo

large projects in C? what about linux?!

82

u/[deleted] Oct 19 '26

[removed] — view removed comment

19

u/septum-funk Oct 19 '26

majority of large libraries that have bindings for everything like SDL and some you listed are also written in C because that's what everything loves to ffi with. large projects in C don't have limitations they just require much much more rules on the programmer's end to keep things organized

6

u/Humble_Anxiety_9534 Oct 19 '26

C++ in theory can be more sloppy but I wouldn't. polymorphism is where the daemon ly.

3

u/septum-funk Oct 20 '26

yes that's true, but a lot of C++'s better features exist just to make code more brief and readable. i'm a bigger fan of C of course, that's plain to everyone, but i don't hate C++ or anything, in fact i hope C continues to add things here and there from C++ mainly namespaces

3

u/sirjofri Oct 23 '26

I wanted namespaces in C for a long time, but then I noticed one thing: If I had namespaces in C, my programs would grow way more complicated than needed. I instead try to use multiple files to structure my code into "namespaces", using the static keyword for local functions. Even though it's a limitation, it makes my life easier by limiting myself to less complex programs in the first place.

Yet still, having namespaces as an option could be very interesting, but I think feature like defer will have a larger impact for me, personally. Though I'm also mostly programming C on Plan 9, which is also special in its own way.

1

u/septum-funk Oct 23 '26

well yes i do that as well, you're going to have to do that if you want to write good C, but having namespaces for libraries would be killer. SDL_Etc becomes sdl::Etc, it basically just eliminates the prefix plague that we have in C

1

u/LordRybec Oct 19 '26

Polymorphism in C isn't that hard. In fact, I think I've worked out at least three models for doing polymorphism in C (and at least two in assembly...). I've never used even one in practical code though. There's always a better way. (Typically unions with a type identifier.) Coming up with those was a good exercise though, in part because when you do it manually, it helps you to realize what a horrific mess it really is. After doing those, I feel no temptation to use polymorphism anywhere, and I don't even feel much temptation to use objects anymore.

(Side note: I program mostly in Python and C. I occasionally use objects in Python (handmade objects, I use built-in objects constantly, because you can't avoid that). I never use polymorphism in Python, because you almost never need to. The dynamic typing means that I can give every renderable object a render() function, every updatable object an update() function and so on, without any need to inherit from the same parent, and together with heterogenous lists that means I can throw them all into the same list and then iterate through calling the appropriate function with no need for any kind of polymorphism. There are some fringe use cases for polymorphism in Python (mainly when inheriting from built-ins designed to be extended), but the vast majority of the time you can just take advantage of dynamic typing and maybe a bit of metaprogramming to achieve the same results more cleanly and efficiently.)

2

u/septum-funk Oct 20 '26

tagged unions are indeed the goat of C and the only reason i use C11 is for anonymous unions. it's genuinely the only feature i use from it, so you can have the type tag and value on the same level

1

u/LordRybec Oct 20 '26

I'm fine with the extra nesting. It's marginally more typing, which doesn't matter anyway. I will admit that I've occasionally forgotten to nest to the right level when accessing, but that's trivial to fix.

That said, maybe I should look into other features of C11. My primary reason for sticking with C99 is that I wouldn't use most of the features in more recent C standards, so why bother? Additional features often add additional overhead, so it takes more than one or two golden ones to convince me. That said, I haven't looked into C11 much. I don't want to use later versions that I have looked into. (C23's "auto" is pretty much pointless, as most types it chooses are easier and shorter to type than "auto" is! And if I'm using C, I'd rather have the explicit typing. If I want implicit typing, I'll use Python.)

But yeah, that is kind of a compelling feature. Unfortunately I do a lot with microcontrollers, and a handful have compilers that don't go past C99 (or in one case, C89), so learning nice but not critical features would just make it harder to program in earlier C.

1

u/septum-funk Oct 20 '26

fwiw i'm pretty sure they're a gnu extension in c99 as well which is nearly portable

3

u/LordRybec Oct 20 '26

I use GCC pretty much everywhere, because it's more portable than any other C. No C complier is 100% compliant, but GCC is close and is at least consistent across platforms and exists for nearly all platforms. So yeah, probably the most portable C.

I'll have to look into that. If it is indeed part of GCC C99, it would be worth my time to use it. I do use other compilers for certain very weak microcontrollers, but they are so far from even being C89 compliant that it makes no difference. (Standard C isn't designed for Harvard architectures, so C compilers for Harvard microcontrollers have to include a ton of extra stuff to do things like specifying which address space each variable is in.) Pretty much everything else I program for uses GCC. It doesn't have C11 support for all of them yet (obscure ones specifically), but if it's in GCC C99, that's not a problem!

Anyhow, thanks! I'll look into that. It's nothing huge, but it would certainly be nice!

1

u/septum-funk Oct 20 '26

The only microcontrollers i use myself are popular dev boards which already support C11 and i'm sure higher (pico, esp32) so i suppose i'm quite lucky 🤣 good luck!

→ More replies

66

u/ArtOfBBQ Oct 18 '26

I also was told a lot of complete bullshit when I started programming and it cost me years of progress

50

u/DDDDarky Oct 18 '26

There are no limitations in what you can/can't do in either of these languages, there are certain (dis)advantages, for example with C you get smaller stdlib size, with C++ you get powerful rich language features.

1

u/Classic_Department42 Oct 19 '26

The libaries are limiting. If you want gui, you can use qt or wxwidget, and both require cpp, right? Yes there are prob some c gui libs, but do they compare favourably to qt?

4

u/septum-funk Oct 20 '26

ever heard of GTK? lol

1

u/Classic_Department42 Oct 20 '26

Yes. And does it compare favourably with qt?

3

u/DDDDarky Oct 20 '26 edited Oct 20 '26

I guess that's also a fair point, many complex libraries and frameworks support only C++, although the gui is often a practical joke, especially on linux. And I personally dislike both qt and gtk (that said qt seems way more advanced).

2

u/septum-funk Oct 20 '26

linux is entirely split between gtk and qt so whether you like more it or not it's a popular alternative

1

u/Classic_Department42 Oct 20 '26

And windows? Embedded?

2

u/septum-funk Oct 20 '26

gtk works fine on windows, if you're doing embedded roll your own ui the fuck you doing running qt on a microcontroller lol

1

u/Wertbon1789 Oct 19 '26

C's stdlib is really a bad argument when compared to C++'s, just because C++ already gives you quite a lot, while you need to wrap around C's stdlib to actually use it. Not even talking about the parts of C's stdlib you should never use, or platform specific functions that are way too convenient, but just not available everywhere for whatever reason.

5

u/septum-funk Oct 20 '26

we ALL writing our own strdup

22

u/IdealBlueMan Oct 18 '26

Handling complex C projects is a whole art form. There are a lot of writeups about various approaches.

Typically, you’d create a directory structure with a shallow tree for each of the chunks of source code, and one or more directories for headers.

You’d generally have one place for executable files.

Each module would typically have its own makefile, and a top-level makefile to build the overall project.

16

u/jacobissimus Oct 18 '26

Outside of systems programming or things where you have to be able to visualize the resulting binary shape—there’s the portability. All languages know the C abi, so if you want to provide something to connect to a FFI that’s a ton easier, or if you want to target arbitrary architectures.

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

9

u/SwordsAndElectrons Oct 18 '26

Embedded is also possible with C++ right?

That depends on what you mean by embedded. 

A x86-based kiosk? Sure.

Modern 32-bit microcontroller? Probably, yeah.

Ancient 8-bit microcontroller? Probably not.

Even though an x86 PC isn't what most of us mean when we say that, all of those can be termed "embedded."

3

u/realhumanuser16234 Oct 19 '26

most mcus have a matching gcc or llvm target or are being phased out. you can generally replace c with c++ everywhere.

0

u/TheLimeyCanuck Oct 19 '26

Arduino is C++ and Arduino devices like Uno, Nano, and Mega are all 8 bit. Uno has been around since 2010 so not really "ancient", but pretty limited by modern standards, and C++ runs fine on it.

9

u/Snarwin Oct 19 '26

Even if you intend to eventually use C++, learning and understanding C will make you a better C++ programmer (and, many would say, a better programmer in general).

The main difference between C and C++ is that there are many features in C++ that allow the compiler to do things for you automatically that, in C, you would have to do yourself, by hand. If you use these features well, they can save you a lot of time, but if you use them poorly, they can make your code difficult to understand and debug. Even for experienced C++ programmers, it is often the case that what you think the compiler is doing is different from what it is actually doing.

The best way to understand what the C++ compiler is doing for you is to practice doing the same thing yourself, by hand--in other words, to take a program that uses a C++ feature like classes, or std::vector, and rewrite it in C. And in order to do this, you will need to have a good foundational understanding of C to start with.

3

u/tastygames_official Oct 18 '26 edited Oct 19 '26

even though they are very similar, they are almost worlds apart, simply because of the (trap) doors C++ opens up with OOP. With C you really can only do imperative programming (of course there is a way to get into true OOP but basically at that point you're better off going with C++), but there is literally absolutely nothing you can't create with imperative that you can in OOP. In fact, I dare say the opposite might be true, as OOP limits you into how things can and cannot be done, so you have to break out of OOP in order to do some things.

Anyway, I love C because it's simple and the logic flows in the code just like it does on the processor (more or less). With OOP, you tend to abstract away the actual computer programming and instead end up focusing on hierarchies and structures and propagation and making all sorts of flowcharts just to be able to figure out where the program logic is. But with imperative, it's literally all right there: line by line.

I recommend learning both, but probably C first. Or if C++, don't start learning classes and OOP until a while later. I've seen programmers with decades of experience simply not be able to do the simplest tasks in imperative programming because they never learned it and can only think in the OOP way, meaning they only think about structures and controlling flow of data rather than the underlying functionality that those complex structures are actually doing. But the opposite is not true at all - imperative programmers have no problem learning and working with OOP. It's frustrating as hell because it's needlessly complex and takes much more effort to read, write and understand, and infinitely more time to debug, but it's very doable.

Do yourself a favor and dive deep into C - maybe even an older standard like C99 or even C90. Figure out how to do everything with that before moving on to "quality of life "improvements"" and "shortcuts" that later standards and higher-level languages offer.

But if after a month of working with C every day you really don't like it and find it too rudimentary, there is no problem with abandoning it and moving on to higher-level languages. Not every programmer needs to be a computer engineer or understand what's happening to the memory or on the CPU every tick. But at least learning about it and getting experience in it will always be a good thing.

8

u/chrism239 Oct 18 '26

Every time you've used 'functional programming' I believe you meant 'imperative, or procedural, programming'.

4

u/pjl1967 Oct 18 '26

Yes. C is procedural. Languages like Haskell, Elm, and OCaml are functional languages.

1

u/tastygames_official Oct 18 '26

indeed. It's been a LONG TIME since I studied the stuff academically (and I did computer engineering and not software, so technically I never actually learnt it as such), but eventually the line in the sand for me became whether or not you can create classes with inheritance and functions all turn into methods. Whereas functions/procedures without hierarchical class structure became "functional" programming (as it's only functions and no classes and you opt for "function over form"(whereas the OOP folks tend to prefer "form over function", as it's all about getting your structure to look elegant, regardless of how complex or nasty or tough to debug it is under the hood).

But yes- I do in fact mean "procedural programming".

Although still to me function = procedure and the functionality is what I'm all about. So it is still "functional programming", even if it's not "functional programming", if that makes sense ;-)

English is a fun language.

2

u/LordRybec Oct 19 '26

You should learn Haskell. That should help you separate "functional" from structured procedural programming. Having functions does not make a language "functional". In programming terms, "functional" refers to functions in terms of math not in terms of subroutines. Programming borrowed the term "function" from math and then blindly applied it to subroutines due to largely superficial similarities. What you view as "functions" are not actually functions. They are programming subroutines that we've incorrectly applied the term "function" to. In a programming context, when you say "function" we all understand what you mean. But when you say "functional", that means (even in programming terms) languages modeled after actual mathematical functions rather than just programming subroutines. Languages like C and C++ are not even remotely "functional" languages and do not use "functional programming". What they use is called "structured programming", which is a subset of imperative programming.

"Procedural programming" technically includes structured programming and functional programming, so it's not a useful distinction here. Structured programming includes subroutines, functions (by the mathematical definition), loops, etc..., which both structured imperative languages and functional languages both have. So C is procedural but so is Haskell, Lisp, and other functional languages. The correct term here is imperative. C is imperative, Haskell is functional. Both are procedural. (Technically functional languages are also structured, but we don't generally called them that. The term "structured" was originally used in programming to distinguish between functionless languages like assembly (which also doesn't even have formal loops) and some versions of Basic and languages like C that have functions and formal loops, all of which are imperative.)

Anyhow, if you say "functional" in terms of programming languages, that term means languages like Haskell, Lisp, and others. It does not mean languages that have subroutines which we've collectively applied the term "function" to, even though they are rarely actually true functions. So if you insist on using the term incorrectly, expect to continue being corrected and misunderstood.

I'm not trying to be rude here, but when people within a community insist on continually using well established terminology incorrectly, it hurts all of us.

1

u/tastygames_official Oct 19 '26

yeah, I know the difference, but I just like the play on words. Like how a knife is "functional" as it "serves a function", so is it in my mind with "functional programming": you write commands and procedures to serve a singular function (change some data, save it to disk, send it across the internet, change the color of an object on screen, etc). But I know that in computer science they mean something else.

I just prefer logical steps instead of "magic" stuff that happens due to structure. I actually like wikipedia's example on imperative vs. functional: https://en.wikipedia.org/wiki/Functional_programming#Imperative_vs._functional_programming

# imperative
int[] numList = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result = 0;
for (int i: numList) {
    if (i % 2 == 0) {
        result += i * 10;
    }
}

# functional
import java.util.Arrays;

int[] numList = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int result = Arrays.stream(numList)
    .filter(n -> n % 2 == 0)
    .map(n -> n * 10)
    .reduce(0, Integer::sum);

so I can see how somebody who is not a programmer will like the functional one more since it reads like a human thinks: "ok, so we we take our list of numbers, then filter them by whether they are even or odd, then multiple each of those by 10, then sum them". But this is too high-level for my taste as you don't know exactly what's happening each step of the way. While this is fine for a simple example like this, in real life when we need good performance and scalability, knowing exactly how each of thse steps of the process work is CRITICAL. And if, for example, we need to modify one of the steps in this process, it becomes a Herculean task as each function is built on top of another function in another class and implementing another interface and so you really have no other choice than to go to imperative programming to get your custom code to run. Either that or stick with the hierarchical logic of functional programming and extend the logic tree to create a superset of commands that now can be controlled via a flag or maybe it's a whole new implementation or something. It drives me absolutely insane when I know EXACTLY what needs to be done but have to fight with some kind of hierarchical abstraction to get it to do what I want. It's like knowing that the fish has to go into the frying pan but all you have are ways to put it in the oven. The burner is right there, as is the pan, so just use them. But instead you have to define a new class that can either be a stovetop or an oven and then a baking tray or a pan, and then make sure they all have implementations of the cook() and check_doneness() functions that are inherently way different but because we need this hierarchy, we must shoehorn our log into this structure. And god forbid we want to bake the fish in the oven and finish in the pan for crispiness - now we have to abstract the cooking process to include a "Listable" interface or something with each node being a step in the process that can be be potentialy infinite even though our use case is simply one or the other.

Anyway, this is giving me anxiety. Time to go back to "functional" (imperative ;-) ) programming in C. Have a nice day!

2

u/LordRybec Oct 19 '26

Ah, I see. Then maybe just make it more clear that it's a joke, so that people don't get confused!

As far as the rest goes, I generally agree. I really like Haskell, but I never use it, and part of the reason is not knowing what is going on under the hood. Most of my programming is low level stuff. Either it's full on microcontrollers, or I'm going super low level number manipulation. This is really easy to write and to follow in C. I can do complex pointer manipulation stuff to work with 8 or 16 or 32 bit partitions of 64 or 128 bit values, and it's still fairly easy to see what is happening. I don't even know if I can do stuff like that in Haskell. And in microcontroller programming, things like order of operations are really important, and I spend a lot of time manipulating registers and such. Order of operations isn't guaranteed in functional languages. I actually think I can do register related memory accesses in Haskell, with unsafe memory accesses, but it's basically imperative at that point anyway, and Haskell does not make that stuff easy. I wrote an Asteroid clone in Haskell, for my undergrad senior project (my idea, as I figured if I could do a real-time game in Haskell, I could do pretty much anything), and it actually wasn't too bad, but it certainly wasn't even remotely well optimized. I'm not sure I'd do a game in Haskell again, due to the optimization thing, but what I do for my daily drive/job just doesn't work in functional at all. Functional is like asking the system for the outcome you want, and then the compiler does its best to do it. That only works if the compiler understands the underlying hardware well enough to know how to achieve that outcome. With imperative you are giving it the steps you think will achieve what you want. That means bugs are more likely, but it also means you have 100% of the power available within the system/OS you are coding for.

So as much as I like functional, only imperative (and especially low level like C) can do what I need the way I need.

2

u/tastygames_official Oct 19 '26

I think I'll just go back and edit my comment to say "imperative" instead of "functional"

1

u/Ok_Reserve996 Oct 18 '26

Thank you very much! Can you give me some examples where the difference is visible? Or will it be something that I have first to experience myself while coding?

3

u/chrism239 Oct 18 '26

My favourite distinction is:

C: mow(the_lawn);

.vs.

C++: lawn.mow_thyself();

2

u/mjmvideos Oct 19 '26

But it could be: gardener.mow(the_lawn);

1

u/tastygames_official Oct 18 '26

it's perhaps complicated to explain to a beginner, but basically a typical C functional programming snippet might look like this:

/* some function that modifies the cart */
update_cart_total(&cart);

/* check prices or something */
for(i=0; i<cart_size; i++) {
  if(cart->item[i].price <= 0) {
    cart->item[i].price = 0;
  }
}

So you just chug along and do one thing after the other and jump into functions whenever they are needed. But for OOP (which C++ tends to be, even though you technically don't have to write OOP) is more like this:

InputParams input_params = InputParamFactor::get_instance()->retrieve_input_params(user_context);
Cart cart = CartFactory::get_instance()->retrieve_cart_by_input_params(input_params);
cart.update();
CartIterator price_check = CartIterator::new({...bunch of data abstracting out the price check iterator logic instead of just programming it...})
CartIteratorHandle h_price_check = cart.add_iterator(price_check);
CartIteratorFactory::get_instance()->perform_iteration(h_price_check);

so you can kinda tell what's going on, but there's a lot of boilerplate stuff to make it all work within common modern paradigms and design patterns, so it just ends up making the code really hard to read. Notice how many extra functions you have to call and variables you have to create just to save yourself from writing out the logic by hand. The whole idea with these OOP design patterns is to have the structure do all the work so you only ever just pass around some configuration settings and everything just "magically" gets done. But the worst part is when you look into one of the functions to see what's actually happening it just looks like this:

void CartIterator::run(IteratorItem *item) {
  IteratorSettings settings = IteratorSettingsFactory::get_settings_for_iterator(item);
  return item->run(settings);
}

so it's a neverending chase to track down where the code is actually being executed as every function is written small and only ever does one thing so it can be unit-tested but this means you never have a full understanding of what's going on without looking through tens (if not hundreds) of functions and files just to track down what's going on.

Maybe I'm biased, but when I entered into software development as a career (after maybe like 10 years of doing it "just for fun"), I quickly was forced into doing everything the OOP way for a lot of stuff and it just really got to me over the years (decades, really), so I'm so super happy to be back in functional programming land where everything is right there in one place and the logic follows top to bottom rathe than having to look through an entire project just to find its entry point.

4

u/frasnian Oct 19 '26

Your contrived "c++" example is an abomination. No working professional would write code like that.

This is how you tell me that you don't actually know C++ and have never really used C++ professionally without actually saying that you don't actually know C++ and have never really used C++ professionally.

3

u/LordRybec Oct 19 '26

Lol! Yeah, I've seen professional C++ code just like that, from those with 5 to 10 years or more of experience. In fact, I've seen worse and then rewrote it in C myself to eliminate the temptation for someone "maintaining" the code in the future to turn it back into that kind of abomination. This is part of the reason I prefer C. There are a lot of bad C++ programmers out there who would write much better code in C because C doesn't leave room for writing code that terrible!

2

u/tastygames_official Oct 19 '26

I once rewrote a core API endpoint for a client that was causing some problems. They were using some framework and had all this "magic" dependency injection stuff going on and the guy who made it was super proud about how clever it was and easily extensible it was (it wasn't - it was only extensible if you had to do add another use case that already uses the same exact data format).

Anyway, it was very slow so I was brought in to consult, and for shits and giggles I rewrote the most complex use case as just a single, straight-shot program with no OOP, no framework - just literally data in -> process -> data out. I didn't even to any kind of optimization (paralellization, caching, more performant data structures) and got a 175x speed boost. I asked if this would be a direction they would like to go in, and the guy who made the system (CTO or head of tech or whatever) told me "that's not really programming!" He was as just as old as I was, and had a degree in something software-related, but seriously thought that unless you use some kind of hyper-abstraction paradigm it's "not really programming". Absolutely blew my mind.

Since then I've encountered more and more "software architechts" who seem to think that you need it to be complex and abstract in order to be "real". My guess is that it has to do with how they were taught - probably skipped the basics and went right to learning the frameworks/paradigms. The worst part? companies (and customers) seem to not care about performance or simplicity anymore. Sofware is continuously rolled out now so anything that doesn't work today can be fixed tomorrow and people are just OK with it.

3

u/LordRybec Oct 19 '26

Like people who think Python isn't a "real programming language". I mean, Basic was widely considered a real programming language, and it was interpreted as well. And modern Python generally isn't even interpreted. It's compiled to bytecode and then run through a sort of emulator. It's basically the exact same model Java uses, except that Python isn't so egotistical that it calls the emulator a "virtual machine", despite no such machine actually existing.

Yeah, anyone can write massive piles of code to do a simple thing. A real programmer can do the same thing in very little code. But too many people take far to long to understand that, and some never figure it out.

2

u/tastygames_official Oct 19 '26

perfect take on python/java ;-)

1

u/tastygames_official Oct 19 '26

it's a generic OOP, not necesssarily C++. But yes - most of my time in the last 30 years or so has been with Java, PHP, TypeScript, C# were the most recent and worst offenders. My last foray was a C++ project (godot) before calling it quits and moving over to C forever. But these design patterns hold true no matter what language. It usually gets that way when it's some sort of framework or platform that everyone uses and it's just awful because it's so generic and abstracted to hell.

Don't take offense - all languages have their merits but I'm just staunchly against OOP at this point in my life because it's always going to get abstracted to hell for the sake of "looking nice" rather than being functional or performant.

Object-Oriented Programming is Bad
"Clean" Code, Horrible Performance
Abstraction Bad? | Clean Code : Horrible Performance
The purest coding style, where bugs are near impossible

8

u/trist007 Oct 19 '26

just use C, it's simpler, not many features. Use less dependencies and write your own. you learn more and can probably compile in 20 years

8

u/Retropolis_1950 Oct 19 '26

IMNHO if you can't do it in "C" it can't be done.The entire trick with large projects involving multiple contributors has almost ZERO to do with the language in use. Defining the project structure and interfaces, as well as the protocols for source control and documentation are the elements of success or failure. Any thought that those definitions will be self driving should be banished immediately. Nothing happens unless someone puts their hand to it and you will need gatekeepers and moderators.

3

u/Maqi-X Oct 20 '26

This is not entirely true. There are many things you would do in other languages but wouldn't do in C because of the features it has and the features it lacks.

4

u/Retropolis_1950 Oct 20 '26

The choice of language based on features, Python for example, is a real thing. But, at the end of the day, that is a matter of convenience more than capability. Which is why I said what I said.

1

u/flatfinger Oct 19 '26

Many commercial C implementations intended for low-level programming are designed around the idea that actions which are not defined by the language will be processed in a manner characteristic of the environment, which will be documented if the environment happens to document it. The C Standard acknowledges this idea when it suggests that actions where it waives jurisdictions may be treated "in a documented manner characteristic of the environment", but fails to recognize an important aspect: implementations will often have no way of knowing which corner cases will and are will not be documented by the environment. Many people seem to think the Standard uses the term "implementation-defined behavior" for actions that many implementations should be expected to process in a manner characteristic of the environment, but that category is limited to actions that all implementations are required to define and document.

On many platforms, the only thing a programmer would need to do that isn't accommodated by standard C syntax would be to force a particular function or object to be placed at a particular address. While non-standard syntax may make some actions more convenient than they would otherwise be, and on some platforms the use of non-standard syntax might be unavoidable, many commercial compilers can do everything that needs to be done--with the one exception noted above--without any toolset-specific syntax.

Unfortunately, the C Standard has yet to recognize a distinction between implementations that behave in a manner consistent with commercial low-level C implementations, and those that treat the Standard's failure to mandate a corner case behavior as implying that the corner case isn't part of "real" C.

1

u/Retropolis_1950 Oct 19 '26

Which language(s) do you use that automatically detects those corner cases?

1

u/flatfinger Oct 19 '26

The language doesn't "detect" them. The design intention of C was that the semantics of p->foo +=5; would be, essentially, "Tell the execution environment to take the address in p, add the offset of foo to it, convert the value 5 to the type of p->foo, and either perform an operation that adds that to the storage at the indicated address (if the platform can do that in one operation), or read the contents of that storage, add five, and write it back." If p happened to hold an address of a structure of *p's type, the effect of that operation would be to add 5 to the value of member foo of that structure, but the implementation would instruct the execution environment to perform the address calculations and accesses in a manner that was agnostic with regard to any significance that address might have. If the execution environment specifies that it has a region of battery-backed RAM from address 0xC0001040 to 0xC000107F, p holds 0xC0001040, p->foo is a uint32 at offset 0x3C, then the above code would add 5 to a 32-bit value stored in addresses 0xC000107C to 0xC000107F inclusive.

1

u/Retropolis_1950 Oct 19 '26

I fail to see how your explanation is a corner case.

1

u/flatfinger Oct 19 '26

You wouoldn't view the possibility that the code might happen to access memory that the hardware might happen to have mapped to a region of battery-backed storage as an obscure corner case?

1

u/Retropolis_1950 Oct 19 '26

I would assume battery backed memory still needs to be managed and is read/write. If it's supposed to be write protected I wouldn't rely on the compiler to enforce that. Dealing with pointers, a real strong point of 'C', is fraught with potential harm. Almost all of which live in the runtime and not compile space. In critical environments pointers are verboten or at least should behave by MISRA conventions.

1

u/flatfinger Oct 19 '26

I would expect a low-level compiler to process actions which access objects through a pointer to be processed as imperatives telling the execution environment to perform the indicated accesses to the indicated addresses in a manner that was generally agnostic with regard to how the execution environment would respond. The compiler should generally neither know nor care about what information the programmer might have about the environment.

1

u/Retropolis_1950 Oct 19 '26

Your responses delve into the philosophical without clarifying your original assessment re: corner-cases. When you say "I would expect" it implies you haven't investigated the behavior of your chosen tools. To digress, I have looked at the code produced to see how the optimizer deals with a coding style and sometimes rewritten code to get a cleaner output. That said, modern tools are so good that is almost never needed but there are still coding paradigms that will produce better outcomes.

1

u/flatfinger Oct 19 '26

Some compilers require the use of toolset-specific syntax to achieve such semantics. Some compilers are not intended to be suitable for low-level programming tasks. If an implementation claims to be suitable for low-level programming tasks without documenting anything special a programmer must do to achieve the necessary semantics, I would treat those facts together as implying either that the implementation will support such semantics by default, or that it is lying about being suitable for low-level programming.

1

u/PyroNine9 Oct 20 '26

There is no corner case there. C (or C++) will emit machine instructions that will cause the processor to perform the specified transactions with memory. Neither knows if it's real memory battery backed or otherwise, or a register that will have side effects. That's for the programmer to deal with.

Other languages (Python for example) will not intrinsically let you assign a variable to be stored into a particular physical or virtual address (though you can implement Python functions in C that will handle it).

4

u/InevitablyCyclic Oct 19 '26

On your last point, yes embedded is possible in c++. But embedded covers a huge range, from an 8 bit micro with a few k of memory to a full Linux system with masses of memory and an SSD.

Arduino is c++, that shows that even the low end can be c++ if you want to and aren't at the point of counting every single bytes and clock cycle. But for microcontrollers you tend then to use a very limited subset of the c++ features. Most (if possible all) memory allocation and object creation is done on startup and forget about using exceptions. It's more c with objects than desktop c++.

1

u/Bona_Fide3 Oct 22 '26

Why bother learning to code? It is useless.

1

u/Ok_Reserve996 Oct 25 '26

Gugugaga gu gu, ga ga?

3

u/Cats_and_Shit Oct 19 '26

In terms of a final executable, there is little to no difference in what you can produce between the two languages.

However if you're talking about libraries then there absolutely is. You can reasonably create complex, reusable data structures with C++ templates that can't reasonably be created in C; and you can write abstract code using things like OOP features and operator overloading that you couldn't in C.

How much any of this matters depends a lot on what you are building. In practice it seems like UI libraries benefit a lot from this kind of thing, but for most other's it's a wash if actually helps or not.

6

u/UltimatePeace05 Oct 18 '26

In my, and many in the handmade community's opinion, C++ is just C with templates. Modern C++ features are horrible and full of traps. The standard template library is, I guess, better than C's stdlib, but not by much... Which is kind of impressive, since C's standard library is horrible. 

The advance of C++ is just that you can define a Dynamic_Array, Slice and Map template structs and then you don't have to deal with weird macros and codegen... everything else is, imo, extra... (if those 3 were actually in C, I would say that C++ has no significant advantages)

But I also use C over C++, so take my absolute hate speech here with a grain of salt...

3

u/Rabbitical Oct 19 '26

I would add properly typed enums, namespaces, static_cast, having the option of references, and auto are nice as well. Probably forgetting some others...

2

u/realhumanuser16234 Oct 19 '26

auto is part of c

1

u/Rabbitical Oct 19 '26

Sorry I always forget that it was incorporated in C23! (The C++ meaning obviously)

1

u/masorick Oct 19 '26

I’m curious about which specifically modern C++ features you consider to be horrible.

2

u/UltimatePeace05 Oct 19 '26 edited Oct 19 '26

The main thing that I've seen the committee do is "improve" the template language so that you can do more and more at compile time, even though it results in some of the least understandable code, I'd say, anywhere... Take: https://github.com/microsoft/STL/blob/main/stl/src/print.cpp which, I think, maybe defines std::print??? or https://github.com/marzer/tomlplusplus/blob/master/toml.hpp Which is a TOML parser (first search engine result). I tried to find the parse function here to link you to it, but I couldn't... :( In my experience, you don't really see this with applications, might be that it's a lot harder to justify there. Might be survivor-ship bias. Dunno...

Although I also particularly hate the memory management. In my opinion, arena allocators, pointers & handles should be the default, while smart_, shared_, unique_pointers should be incredibly niche tools... (not to be confused with C++ std::allocator which allows overriding allocators for different types??? for some reason..?). This is very much a per-problem sort of thing and every allocation strategy has at least some use case... If you want more things to read there is gingerBill's article series on allocation strategies: https://www.gingerbill.org/article/2019/02/01/memory-allocation-strategies-001/ and Ryan Fleury's big blog: https://www.dgtlgrove.com/p/untangling-lifetimes-the-arena-allocator

But like, go to cpp history or whatever. Throw a dart. Chances are, I will dislike the change (if I have the slightest clue what it is).

2

u/masorick Oct 20 '26

Thank you for your response. To be honest, as a C++ developer, I always find it wild when people rant against "modern C++", because I’m my opinion, most of the changes from C++11 onwards (auto / decltype, lambdas, constexpr, variadic templates and even the dreaded move semantics) have only made the language more useable, and most of what I would consider terrible are things that were there from the beginning, stuff like OOP and iostreams.

In the end, it comes down to a difference in philosophy. What I like about C++ is that it allows me to build powerful abstractions that I can use within the language itself (for instance, I don’t need defer in C++, since I can build it myself using destructors, lambdas and templates), whereas C is quite limited in that regard (you can use C to build an interpreter for a high level language, but not to augment C itself, so to speak), but I also understand why some people would rather deal with all the complexities that come from C itself being simple.

As for memory management, I agree that C++’s type system makes it more difficult to use arenas, but I also like that smart pointers are a thing (if only there was a warning that told people that a shared_ptr is probably not what they need, sigh).

2

u/thecratedigger_25 Oct 19 '26

I code C++ like it is C but I encapsulate them in namespaces and use the more modern features to make the code more compact. Preferably C++20.

Keeps the code organized and simple than just doing oop. C makes it easier to learn C++ and get into data oriented design.

1

u/LordRybec Oct 19 '26

I generally use C99. The only thing I think I'd like to see from C++ in C is namespaces. That said, I code C as if it had namespaces, and I just do NAMESPACE_ as the namespace prefix. That works really well, and it has been a common convention in major C libraries.

If I had to use C++ though, I'd do it similarly to how you do. A lot of C++ features actually make the code larger, not more compact, but features that make it more compact without making it harder to debug wouldn't be a problem for me. (That said, I don't want to have memorize a ton of "syntactic sugar" devices that make code harder to read and only make it faster to type. Faster typing isn't useful, because the bulk of programming time is spent working out logic, which can often be done while typing. So faster typing just means you aren't typing as much during the time you spend working out logic, which doesn't save any actual time.)

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.

2

u/Classic-Rate-5104 Oct 19 '26

Start learning the basics in C, for example structs, pointers, arrays etcetera. C++ is too overwhelming to start with

1

u/randomguy4q5b3ty Oct 21 '26

The goal of this post is to understand how and if C could fit me more with my goals

I'm sorry, but what exactly are your goals?

1

u/Plus-Dust Oct 22 '26

You can use both for big projects or small, embedded/kernel or application development (e.g. GTK is C native). Personally I use C++ and just opt into the features you want--you can write C++ with no double-colons in sight that's almost like C with more features, so I don't see a ton of downside in choosing C++. There are a few edge case instances where C has alone gotten envy-producing syntax that C++ hasn't, but not much ime.

1

u/d954mas Oct 22 '26

C is awesome. Simple, eady to understand. C++ in big projects is much harder then c

1

u/NoSpite4410 Oct 22 '26

C is writing hardware commands. Every C statement touches hardware.
Keep that in mind, because then you can do anything, and everything in C makes sense.

C is for creating binary interfaces. Data is binary bytes to C, and that is all it is.
All the data-centric stuff is built on top of the binary interface.
OK there are numbers and math and some help for strings, but it is still just bytes and memory and instructions on how to move them around and change their values.

C++ is primarily for creating object interfaces (in binary mode). Instead of passing bytes, you are passing objects and converting them into data and treat them like little mini-programs each that can do its thing and consume and produce other objects and data.

C++ is all that plus an object layer, and a type systems that understands objects.
The C++ compiler does auto-generation of all the basic object creation, assignment, destruction, and ownership functions for you, unless you make your own, and does
some auto-initialization that C does not.

The C runtime is the leanest and fastest around, so it leaves most things up to the coder to implement.
The C++ runtime is a lot fatter, but about the same speed for most stuff, because it uses the same compiler and libc for I/O.

C structs are just passive transparent aggregate consecutive contiguous regions of memory.
A C++ class is mostly just a C struct with a bunch of function pointers in a virtual table in the runtime that it chooses based on the object model ( binds functions to class types).
This is important, because C libraries pass structs to C++ code all the time in system libraries, and they are binary compatible.

1

u/Antique_War_9814 Oct 23 '26

You are confusing language with platform portability. Posix ect...

1

u/m_yasinhan Oct 24 '26

it is not called limitations. They are design differences, and what makes C a minimal and beautiful language.

1

u/Low_Lawyer_5684 Oct 24 '26

It is nearly impossible to learn C++ without learning C first. If you are fluent in C, then you can learn C++ as a "better" version of C.

1

u/noobyscientific Oct 19 '26

Limitations with a language, that literally talks to the memory and processor, literally don't exit. C can do anything, and I mean literally anything.

Thing you probably interpeted as "limitations" are likely things that would be harder to do in C than C++.

You can use any language for your idea, but C++ might be the way to go.

1

u/TaronVale Oct 26 '26

My two rules of programming:

  1. You can do anything in C.
  2. If it can't be done in C, it's not worth to be done!

1

u/TheTomato2 Oct 20 '26

The problems with C++ become apparent when you become an expert, you ask yourself "why would you design it like this, I would rather just go back and use C like a caveman."

However most of the things you seem to think matter don't really matter. Classes and OOP don't really matter. You can do whatever you want either way. What does matter, poorly designed or not, is C++ has meta programming built into the language and you can use it for generics. With C you have do some stupid macro or typless stuff to even come close to emulate it.

Everything else is done leagues better in other languages than C++. There no "limitations", language features about convenience and time and possibly security and nothing else. Your "language" is just a translation layer for a, compiler to spit out assembly, there isn't like a "limitation" there in these lower level languages.

1

u/QuirkyImage Oct 20 '26 edited Oct 20 '26

You can do anything in C there are ways to implement features of C++ but sometimes I think the beauty of C is not having to use them in the first place. You cannot get much more complex than the Linux Kernel. But I would still choose what I consider the best language for the job for example there are areas of network based software where I would jump straight into GO.

0

u/timrprobocom Oct 18 '26

It's not a technological limitation. Anything possible in one can be done in the other. Remember, the C++ compiler used to be a front end that generated C code to be compiled.

It's concepts. C++ allows you to express more complicated concepts in a more natural way. That's very soft and fuzzy, but it makes for better programs with less programmer effort

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.

-1

u/rubidus-api Oct 19 '26

I'd like to share a somewhat related experience of my own.

I'm an amateur programmer, and recently I've been experimenting with creating a simple systems programming language with the help of AI. There's no practical goal behind it. I was just curious about what AI could do, and I thought it would be fun. Along the way, I've been reminded of just how difficult it is to define the rules and constraints for even the most basic data types.

When designing integer types, the obvious approach is to define them by their bit widths. So I introduced unsigned types like u8, u16, etc., and signed types like i8, i16, etc. So far, so good.

Then came the question of how these types should interact in arithmetic expressions.

Having learned from C just how troublesome implicit conversions and differing integer ranges can be, I decided to introduce two keywords, narrow and widen, for explicit conversions. Arithmetic would only be allowed between operands of the same type, and everything else would be rejected. Still manageable.

Then I needed types for sizes, indices, and pointer differences. In C, we have size_t for object sizes and ptrdiff_t for pointer differences. But what should their widths be?

I wanted my language to support everything from 8-bit microcontrollers to 64-bit and potentially wider architectures. Simply using u64 everywhere wasn't an option. So I ended up introducing usize and idiff, with implementation-defined widths.

And then I ran into another problem.

Suppose usize is 16 bits on one platform and 64 bits on another. What happens when you need to perform arithmetic involving usize and u32? Should you use narrow or widen?

The answer depends on the target architecture. A conversion that can preserve every possible value on one platform might lose information on another.

So I needed yet another keyword, cast, for conversions that don't fit neatly into either category. Actually, the AI had already introduced that keyword for something else. But even with it, deciding exactly what should happen in each situation is far from straightforward.

And that's where I am now.

There are still plenty of unresolved questions. Different architectures have different natural integer widths and different performance characteristics. Is it really a good idea to use explicitly sized types like u8 through u64 for everything? Should I introduce architecture-dependent integer types like C's int? And if I do, how should all the arithmetic and conversion rules work?

I haven't even started on pointers yet.

Different pointer types may have different representations and sizes, and architectures like CHERI can have pointers that are wider than the native integer word. The compiler should ideally be able to generate efficient code for all these cases.

I've been having AI research how existing languages handle these issues, and I've spent quite a bit of time thinking about the trade-offs. But making these decisions is surprisingly difficult.

And I have this uncomfortable feeling that, after working through all these problems, I'll eventually end up creating yet another language that makes almost exactly the same compromises as C.

Anyway, that's my recent experience. Now, here's how I think it relates to your question.

C isn't a particularly large or complicated language, at least compared to C++. But it runs on an enormous variety of platforms, and its specification contains a surprisingly intricate set of rules and compromises intended to balance portability, efficiency, and implementation freedom.

Sometimes those rules interact in unexpected ways, as anyone who has encountered bugs involving strict aliasing or undefined behavior can probably appreciate.

The C++ standard is roughly two thousand pages long. Can programmers and compiler implementers really keep all that complexity under control, especially when building something like an operating system that needs to work across many architectures with very different characteristics?

And what about massive projects whose source code must be maintained for decades? How easily can they accommodate a language that evolves as rapidly as C++?

I don't think C++ is a convincing replacement for C in all those environments. Personally, I'm not particularly fond of C++ anyway, so I'll admit there's some bias here. :)

What about newer languages like Zig and Rust?

They're already doing impressive work, and I expect them to continue taking over areas traditionally dominated by C. But I don't think we're quite at the point where they can replace C across its entire range of applications.

This isn't necessarily about raw execution speed. Rust and Zig can generate very efficient machine code. It's more about the maturity of their toolchains, the breadth of architectures and environments they support, their long-term stability, and how much control they give programmers over the resulting binaries and their dependencies.

C has had decades to develop its compilers, ABIs, libraries, and platform support. Replacing that entire ecosystem is a much bigger challenge than simply generating fast machine code.

I suspect newer languages will eventually catch up in more of these areas, just as C compilers themselves matured through decades of optimization and refinement. But for now, I think C still has some time left.

So here's my conclusion.

C occupies a rather awkward, subtle, and strangely well-balanced position that's difficult to explain in a few sentences.

Its portability rules, undefined behavior, minimal abstractions, integer types, memory model, and close relationship with hardware can all seem rather clumsy. Some of its compromises look almost arbitrary, and some are genuinely unpleasant.

But when you start facing the same design problems yourself, you begin to understand why those compromises were made, even if you don't necessarily agree with them.

It's not that C is an ideal language. Far from it.

It's that C has settled into a peculiar position where almost every apparent flaw is connected to some other constraint or trade-off. Fixing one problem often means introducing another.

And there it remains, somewhat awkwardly, but remarkably firmly.

Not because it's perfect, but because finding a replacement that preserves everything people value about it turns out to be much harder than it looks.

-4

u/I_Messed_Up_2020 Oct 19 '26

As the century progresses I think knowing C++ will give one a more diverse employment landscape.

Here is the view from an AI perspective provided by AI.
Frontier AI models (like GPT-4, Claude, or DeepSeek) are not written in just a single programming language. Instead, building and running them requires a multi-layered software stack where different languages handle different parts of the pipeline:

1. Python (The Orchestrator & Research Language)

  • Role: High-level model architecture design, training loop coordination, data preprocessing, and research prototyping.
  • Why: Python is the default language for the machine learning ecosystem. Frameworks like PyTorch provide Python APIs that researchers and engineers use to define neural network layers, set up attention mechanisms, and orchestrate massive training runs.

2. C++ (The High-Performance Engine)

  • Role: Core runtime operations, memory management, and production inference.
  • Why: Python is too slow and has too much runtime overhead (like garbage collection) to efficiently drive thousands of GPUs at scale. Underneath the Python code, frameworks like PyTorch rely heavily on a C++ core (such as ATen) to execute heavy lifting. When deploying models for real-time user inference, C++ is heavily used to minimize latency.

3. CUDA & Triton (The Hardware Accelerators)

  • Role: Custom GPU computing and kernel optimization.
  • Why: Training frontier models requires squeezing every drop of performance out of clusters of tens of thousands of NVIDIA GPUs. Engineers write low-level CUDA C++ or use domain-specific languages like OpenAI's Triton (which lets developers write GPU kernels in a Python-like syntax) to custom-fuse mathematical operations, optimizing how data moves through GPU memory.

Summary

If you look at a frontier AI lab's codebase, you will see a blend: Python on the surface to glue experiments and training scripts together, driven by C++, CUDA, and Triton underneath to handle the blistering computational demands of matrix multiplication at scale.

3

u/noobyscientific Oct 19 '26

What are you even talking about.

2

u/LordRybec Oct 19 '26

Not sure responding to a lazy "I asked the AI" comment is worth the effort. I ask AI stuff a lot, and 99% of the time it misses a lot of things and says at least a handful of things that are wrong. On top of that, the OP could easily have asked the AI themselves, if they wanted a low quality, canned answer, based on random garbage inexperienced people say.

C++ currently has a larger job market than C, but the C++ market is constantly bleeding people to newer, more popular languages. The C market has largely already bled off what it was ever going to, to C++, so the C job market is probably going to remain more stable in the long term, while the C++ job market is going to continue to bleed off people to languages like Python, Erlang, Ruby, Go, etc... as those languages improve in performance and as technology gets faster so that performance and memory differences matter less.

Of course, that assumes that things will stay largely the same in terms of what kinds of applications are being made. I suspect that this will not happen. In fact, I already see a shift starting in consumer purchasing habits as well as business applications for computing equipment. What I'm starting to see is a general shift away from high power, general purpose computing devices and toward lower power special purpose devices. A decade or so ago, if someone wanted voice control they would have designed an application for a desktop or laptop computer. In fact, that's what Cortana was, along with some of the other "voice assistant" software. Most of those weren't popular enough keep developing. MS has already abandoned Cortana, and other major voice control software has largely been moved into special purpose devices, like Alexa. Communities of people rolling their own special purpose systems, like "writerdeck" systems, are growing, as people realize that they are more productive on a single-purpose system that does not have built in distractions. Raspberry Pis are making this extremely easy, but they are massive overkill in most cases. People building single purpose devices have been shifting toward cheaper, less powerful microcontrollers like the RP2040 and RP2350 (and for midrange, the Pi Zero and Pi Zero 2 systems are so popular that they are currently out of stock nearly everywhere except scalpers who are charging 6+ times the price). The lower level you go, the closer you get to C. A lot of these can be coded in C++, but single purpose systems rarely require such complex code that C++ has any advantages, and people looking for the cheapest system they can built are going for the lower memory and better performance of C.

So if we consider the current trends in computing, it actually looks a lot like modern technology is starting to move away from the kind of massively powerful systems with tons of memory that C++ is better suited to and is starting to move toward a larger number of smaller, cheaper, more compact devices that each do just one thing but do it extremely well, and C is pretty much the best language for that, once you get past the hobby level. It's currently mainly hobbyists driving this, but as hobbyists show off their devices, I'm seeing more people who are not technologically inclined asking where they can get their own. There are already companies trying to fill these markets, but they are struggling to keep up, because they are using languages like C++ that require them to use significantly more powerful hardware than is strictly necessary. You can get a $200 writerdeck with C++ software, but I can make the same thing for under $30 (I'd have to charge around $70 or $80 to cover my time) if I use C, because I can use a much cheaper processor, and mine will do more than the $200 one (like, make it easy to transfer files to your desktop or laptop for publication). Cyberdecks are starting to take on practical uses rather than just being decorative, and again, demand is increasing. I'm currently working on some projects using ultra-low resource microcontrollers, precisely to get into this market while it is still fresh, and I have some friends who have already developed and are now selling single purpose devices mainly programmed in C or light C++ (light meaning few or no objects and avoiding the use of features with high resource costs). If my business ends up getting off the ground within the next 5 years or so, I'll probably be looking to hire C programmers, not C++ programmers, because microcontroller cost will a significant factor as production scales up, and I can use much cheaper and lower power (in terms of energy, which means much longer battery life) microcontrollers if the firmware is written in C.

This is something the AI can't predict though, because it only has the past to work with, and it is trained on past data not on what is currently happening in real-time. Further, when you ask the AI something, it has maybe 20 seconds to search the internet for relevant data, load it, analyze it, etc... On the other hand, I've been watching these communities that are often hard to find for years now, and I can see what's going on within this field in general more clearly than an AI that is trained in everything and thus specializes in nothing.

The reality is, people have been calling C a dead language for over 10 years. It's not even close to that, but the AI only knows what it sees, and more people are incorrectly calling C a dead language, because they aren't aware of where or how much it is still used, so that's what the AI will echo. If the majority of things people claim online or in writing are wrong, and the AI is trained on that, the AI will also be wrong, because it is only repeating what it has heard. Relying on generalist AI for predictions of the future in specialized fields is extremely unwise, because it will be wrong the vast majority of the time. AI is not some kind of prophet, so quit treating it like it is!

2

u/kat-tricks Oct 19 '26

fucking meat proxies...