How many of you use C for game programming?

Started by
107 comments, last by Washu 13 years, 1 month ago
I use C++ at work, but like to write my personal game projects in C. When I write code in C, I tend to put the data first and be a little more pragmatic about architectural decisions. I don't waste time on building complex class hierarchies with the intent of reusing them again - I just make the damn game. C is also a lot easier to bind to other languages like Lua, Python, or Mono, and in those languages you can do all the OOP you want. C is also a little easier to throw on an SPU.
Will Miller | Game Designer | Big Huge Games
Advertisement
I avoid C like the plaque. It doesn't have anything that C++ has like templates, smart pointers, containers, string classes, etc. I personally C a waste of time anything above system/hardware level.
Yes. For an iOS game.
Latest project: Sideways Racing on the iPad

Yes. For an iOS game.


iOS uses Objective-C ;)

'Tachikoma' said:

Yes. For an iOS game.


iOS uses Objective-C ;)


To be clear, the iOS APIs are written in Objective-C, but your game code doesn't have to be. You can mix C and C++ with Objective-C very easily.
Will Miller | Game Designer | Big Huge Games
Never, I see very few advantages in using it. If accessors are a pain then just make the variables public.

Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

I find C too low level to get any real work done efficiently. The lack of standard containers really drags things down.

Other than that, it's a much nicer language than C++ to use. It's simpler and doesn't have nearly as many caveats, which allows you to better focus on the problem at hand. C tends towards minimalism: "what's the simplest way to make this work?" C++ entices you to think big: "how can I make this more general reusable"? (This is a trap, don't do it!)

That said, given a choice I avoid low-level languages completely. You don't need to use C++ to create a game and you don't need C to create a reusable component. Once you manage to accept that (it's harder than it sounds) a bright new world of possibilities opens up! Life is too short to spend it working on yet another container (or waiting for it to compile).

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

Well, I can work pretty fast with C. Reusable (or easily modifiable) stuff has been gathered through the years of coding. Okay, I usually don't give a shit about nice design (and I'm too lame to go multithread). I need stuff to load? A global 1million sized array! I need a flag or a state variable? A global variable, huhhh

Oh and one of my big gripes is malloc and free are annoying as hell to use with all their casting clutter.



If you need to cast, then you're trying to compile a C program as C++. My favorite idiom is:
Type *var = malloc(sizeof *var);
free(var);

This is less brittle, more readable, and the compiler will tell you if there's no prototype for malloc(). I don't know how relevant that last part is anymore. Maybe it could cause a problem if sizeof(int) isn't the same as sizeof(void*)?

But, I still agree that there's not much use for C in game programming. The only place I could see using it would be as a lighter choice than C++ to drop down to from a higher level language, whether for speed or gluing bits together. In those cases, I see myself using mostly the C subset of C++, and C++ isn't as good at being C as C is.
I might get flamed for this, but oh well, I'm used to it. I think C++ promotes alot of bad programming practice and laziness, especially for beginner programmers. I don't hate C++, but I prefer straight forward C over some class/template crazy C++ code. TBH, I don't even see what makes most of those features even useful to begin with. Almost everything you can do in C++, you can do in C, but just requires a bit more effort.

I wrote my first 3rd person shooter game in C. Saw no advantage in using C++ whatsoever, and it was easier to follow/maintain.

This topic is closed to new replies.

Advertisement