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

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