r/cpp • u/HolidayNo84 • Jul 02 '26
Why use c++ over c for game development?
Isn't c++ overkill for most games? I think with good architectural decisions you can make decent 2d and 3d games using only what's available in c without the higher level concepts introduced in c++? Do you think I'm being stupid here? Am I missing something? I'm only just starting to learn c making simple games leaning heavily on Raylib and ECS architecture.
0
Upvotes
16
u/mredding Jul 02 '26
Why use <insert language here> over <insert language here>? It appears NO ONE can answer the question, so I think that suggests it's a bad question, bad framing, SOMETHING.
These are completely different languages. They're all Turing Complete, they all follow Curry-Howard Correspondence, they're all high level expressive languages targeting an abstract machine...
You could write a game in assembly, like Roller Coaster Tycoon was, or Java, like Minecraft was...
You pick what meets your technical requirements, what can get the job done, what you can get the job done in. If all you knew was QBasic, I'd guess you're writing your game in QBasic; no one has to know or care. And if QBasic was inadequate, I guess that forces your hand that you'd have to learn something that was. Doesn't really matter what, so long as it gets you there.
Yes, that's true.
Applying your own logic, C is thus overkill. You don't NEED to use C to make a game - so WHY NOT just code in assembly? Why not code in straight binary? Assembly is a 1:1 correspondence to op-codes, but not specifically which. You can skip the middle man...
Since the logical conclusion is absurd, it still suggests the question has a flaw.
Without being critical, yes, I think you're missing the point. You can naively misapply any paradigm, idiom, or abstraction, and get spaghetti. An expert will have enough knowledge and awareness to use the tools available to them concisely. When done well, one gets more and better for less.
39
u/gokufan300 Jul 02 '26
games really like being object oriented
6
u/blipman17 Jul 02 '26
Because std::vector and friends are really good. Re-inventing basic containers and algorithms from scratch everytime you need to do higher order operations between two datasets is wasted time, effort and just yields worse results.
6
u/KFUP Jul 02 '26
I guess thinking C++ is an overkill yet going with the real useless overkill that is ECS is what you get if you learned programming from youtube.
46
u/EvilPettingZoo42 Jul 02 '26
Programming pure C kinda sucks compared to even using C-style C++. If you have something like a mutex you have to manually initialize it at start, have to manually lock and release it in functions and it’s easy to get into cases where you forget to release before you return. C++ simplifies these things plus many more with no real downside.
27
u/TheAdamist Jul 02 '26
Once upon a time games were made in assembly language, c is overkill but will make you far more productive
25
u/Thesorus Jul 02 '26
how do you define overkill ?
C++ is better than C in most cases for large codebase.
11
u/timbeaudet Jul 02 '26
Why are we comparing one language to another; use what works for you.
It's been too long since I've used actual C, and even then so little experience with it, that I may not recall subtle differences properly enough to discuss this. But why do I personally use C++ over C?
For me C++ avoids a ton of boilerplate stuff that I see in soo many C api's. I like having constructor/destructors to initialize/cleanup automatically. I like options to have object.foo() vs foo(object) or having an array<> that already knows the size and other standard library containers or helpers.
You can make good architecture decisions in any language, just as you can make bad ones in all languages too. So... use what works for you.
20
u/El_RoviSoft Jul 02 '26
C++ usually have better optimiser than C because language itself has more context due to templates, crtp and other things. Also OOP is important for gamedev.
ECS is rarely used. Also RAII is extremely important for resource management. Multithreading is marginally easier. I have shit tons of arguments more.
8
u/berlioziano Jul 02 '26
For anything but small games, your C code will become one of this two posible patterns
There are many opensource projects that use C and are OOP, gnome glib/gobject, redis or the linux kernel. Those would have been easier to code and maybe the compiler could have done a better job optimizing if using C++
7
u/slithering3897 Jul 02 '26
You'll take containers/namespaces/templates away from my cold, dead hands.
4
u/Umphed Jul 03 '26
C just kinda sucks for modern apps man. You'll be writing alot of code that you dont have to. You'll do that in C++ too, but C has basically no useful abstractions for modern app development.
1
u/xoner2 Jul 05 '26
Classes without vptrs is just syntax sugar over C structs. And just that is already an improvement; dots instead of arrows is good for the eyes.
There's many more.
This question is kinda trivial to answer...
1
u/Total-Box-5169 Jul 09 '26
Syntax candy that allows to write truly comfy libraries that don't sacrifice performance, simple as.
10
u/AnyPhotograph7804 Jul 02 '26
If C would be good for game development, then everyone would use it. The point is, with C++ you write less sourcecode, you have better type safety, you have a very usable standard library etc.
With C++ you need just way less effort to achieve something. And seriously, C is a very terrible language, IMHO.
6
u/BrokenBurrito128 Jul 02 '26
Folks that start on c and try out c++ tend to write c++ that still looks like c instead of taking full advantage of the language. Things i've noticed C devs tend to not use are
Anecdotally, I have noticed that doing things in C just tends to take longer. That's not to say you can't do it, or that your game will be better or worse. At the end of the day, C and C++ are roughly as performant (1) as each other, and it's just about which one you and your team are more comfortable/faster with.
3
u/lowbuzz :illuminati: Jul 02 '26
Yes you can, but developing as a hobby is a completely different ballpark than doing professional games as a company. There are so many factors that will drive a developer to c++.
3
u/therealhdan Jul 02 '26
C is certainly and obviously sufficient for making games, or any project really. There is nothing C++ can do that you can't make C do with enough clever coding.
But in my experience, the value of using C++ over C increases as the size of your project grows.
Object Oriented design was invented (if you accept SIMULA as the basis for OOP) for doing simulations of real-world systems. Depending on your game, this may be a large factor in what it does.
Constructors/Destructors make building robust systems that don't leak resources easier to design and use.
3
u/pjmlp Jul 02 '26
C was already outdated in the 1990's, it is only UNIX and embedded that kind of keeps it going, along industry standards like POSIX and Khronos.
C++ is a kind of Typescript for C, you can do all the traditional C mess, or take advantage of C++ language features for more secure code, and basic stuff like proper arrays and strings.
2
u/gosh Jul 04 '26
less code to manage, much of coding is about manage code
3
u/_Noreturn Jul 02 '26
Because C++ is better for any non trivial program.
You have way better luck using C style C++ with classes and that makes your code much much better
2
u/tstanisl Jul 02 '26
C is fine for game development. Most oop, generic data structures, and RAII can be achieved in C with some tricks or extensions. The problem is that libraries written C++ cannot be used in C without a lot pain. This causes never ending one way migrations.
1
u/usefulcat Jul 02 '26
The advantages of c++ may be more obvious in a larger, more complex game. When the game is relatively small it's easier to keep all the relevant details in your head, but as it gets bigger that becomes increasingly impractical. You may not have hit that limit yet, but if your game continues to grow then at some point you will. That limit is effectively greater in c++ because it has better support for creating abstractions.
For example, most non-trivial C programs end up with a one-off implementation (or frequently several) of something akin to std::vector, because a resizable array is such an incredibly common thing to need. But compared to understanding how std::vector works, in C it's tiresome to have to keep in mind all the details related to lifetime, reallocation policy, ownership, etc. for a bunch of different dynamically allocated arrays.
Or virtual functions. Obviously you can implement the same thing in C, but unless you need something unusual there's no benefit to doing that compared to using virtual functions as-is in c++ (and if there is a significant benefit to rolling your own, you can also do that in c++).
I could go on but hopefully you get the idea.
1
u/5477 Jul 03 '26
C++ has many features that are very beneficial for game development. Operator overloading allows you to implement arithmetic operators for vectors and matrices. Function overloading allows you to do things like
length(x)without separate functions for every single type. Templates allow for custom containers and generic behavior. These would need macro implementations in C, or custom reimplementation each time.1
u/TrnS_TrA TnT engine dev Jul 03 '26
Like others said, C++ has a lot of features that C doesn't to make it easier for you to write code. Eg.
reflection can help you with codegen, serialization, and more (see wg21.link/p2996 proposal + other papers)
C++ can make your ECS type-safe and easier to use with templates (check out EnTT)
Coroutines fit nice into gamedev, for doing things like animations, boss behaviors (in phases), and whatnot; when you see people talking about behavior trees or other ways to implement AI, most of them map really nicely to coroutines.
destructors are pretty useful, if C had
deferit would have been closereverything else other people mentioned
1
u/nuclear868 Jul 05 '26
Because it is 2026 and
- we do not want to reinvent the wheel and use dangerous macro hacks to implement a poor man's std::list or std::vector or std::map or any other container, working with various types.
- we do not want manual memory management, where every malloc should be paired with a free, which if you forget, you get a memory leak.
- we need things like polymorphism, abstractions, lambdas (with capture), function overloading, automatic resource cleanup, templates, various kinds of containers - things that we have in C++.
I think C is too ancient for the requirements of the current world. Writing drivers, kernels or very optimized code for a platform with limited resources in C is maybe OK. But writing a full-blown game with a lot of stuff happening and a lot of internal dependencies will be a pain in the a*s to write in C.
1
u/RogerV Jul 05 '26
The RAII, the smart pointer template classes, the container template classes, the ability to have safer by default semantics of C++ approach vs C approach - these things are all very real benefits. And especially for when dealing with relatively complex programming domains. Games can certainly qualify as such.
1
u/Raknarg Jul 07 '26 edited Jul 07 '26
I don't think I would rather use C for literally anything, coming as someone who started with C and did my first job in C and have since moved on to C++ and not looked back. There are so many things I'm missing from C++
Idk can you think of a good reason you'd actually want to use C over C++? Unless you just think abstraction is bad I guess.
1
u/hellfoundry Jul 15 '26
Try reading the Doom 3 source code. It's C++, but done in a way that most C developers would feel comfortable. The best of both worlds.
1
u/Resident_Educator251 Jul 02 '26
Cause organizing concepts and ideas in namespaces sure beats having to exhaustively prefix every type and every api with namespacing...
Otherwise... you have destructors in C now, you don't need exceptions, procedural code is fine; but them namespaces... killer feature...
1
u/Weshmek Jul 02 '26
You can absolutely make games in C; games such as DOOM and Quake were programmed in C, and many others even up to the present day.
The caveat is most of those games were developed by small teams and have small codebases by modern standards. C++ definitely has advantages with scale and code organization, which can be vital for large projects with multiple people. Huge C projects with massive teams exist, though, so it's not impossible to make a modern leading-edge game in C, but I'm guessing you'll have a hard time convincing people with experience in the industry to restrict themselves to pure C, just for the sake of it.
If you want your game to be portable to absolutely everything, then C is the language to use. If you look at all the features of C++ and this, "I don't really need any of that for what I'm making", then use C. If you just really like C, then use C.
0
u/Longjumping-Sweet818 Jul 02 '26
You can definitely make games in C. Plenty of games are made in C. But there is a scale of how comfortable it is to make a game, and C is pretty low down on that scale. C++ is higher and even higher than C++ there are things like Haxe and Unity/UE. You can use C, but if your end goal is to really make a game, you would be way better off higher on the scale.
If your goal is just to learn the ropes, you might as well use C.