Portable game engine - C or C++?

Started by
14 comments, last by meeshoo 13 years, 7 months ago
Hello guys,

I've begun research for coding a cross-platform, portable game engine (rendering engine at first). Before you ask, this engine is not because I want to build a specific game with it, it is more of an exercise, a general purpose rendering engine and then game engine that can be used on a multitude of platforms.

When I'm thinking about portable, I don't just want it to be for Windows/Linux/Mac, but also for portable devices like IPhone, Android and other known and well established platforms.

The problem is that I recently read a book (an OpenGL ES programming guide) released in 2008 in which it states that C++ is not supported very well on a multitude of mobile platforms, and it is better to choose C as a programming language for them.

I worked using both of them for more than 10 years now and I'm experienced with both, that is not an issue, however, writing a full blown game engine in C can be a difficult task, and C++ looks much more fit for developing such a software package.

My question is: should I go on with C++, hoping that more and more platforms will support it fully or go with C, and which are the arguments behind your advice?

Thanks.
Advertisement
I don't know of a relevant platform where C++ is not well supported. Even Arduino (a tiny microcontroller) can be programmed in C++.
Well, in the opengl es 2.0 programming guide I've read about, on page 342, there are the following issues stated:

- lack of RTTI support on some
- lack of exceptions support on some
- some platforms don't have STL
- lack of multiple inheritance on some platforms

link to book: http://www.amazon.com/OpenGL-ES-2-0-Programming-Guide/dp/0321502795/ref=sr_1_1?ie=UTF8&s=books&qid=1283362309&sr=8-1

[Edited by - meeshoo on September 1, 2010 12:21:27 PM]
iPhone, Symbian and Android all have full c++ support (including exceptions and stl). In case of Android it's supported by an add-on, but still it works.
Most of that is stuff you probably wouldn't use on a mobile platform game engine anyway. Anyway, that's not the point. C++ is a superset of C. So you can choose to either use C, giving up all the benefits of C++, or you can use a limited implementation of C++, giving up only some of the benefits. Put in that light, which would you choose? In any case, mobile platform C++ implementations are improving all the time. Most have full support, and those that don't are rapidly getting it.
Quote:Original post by meeshoo- lack of RTTI support on some
- lack of exceptions support on some
- some platforms don't have STL
- lack of multiple inheritance on some platforms

Mostly these features now-days works on most of embedded platforms, but very often people doesn't use them for some reasons - either performance or size of generated code, or something else (poor performance for standard library implementation, old cross-platform compiler versions with bugs, etc).

Really - how often do you need RTTI on small game engine (for iPhone, for example)? I've never used C++ RTTI myself even on desktop platform, except indirectly by third party library (LLVM, boost).

Vanilla C++ (think C + objects/inheritance) imho would be fine for such game engine. Just don't rely on RTTI/exceptions and you will be fine.
Thanks for all your replies, it was very helpful. I will continue then with C/C++ combo that always works best, leaving fancy C++ stuff aside, but benefiting from objects, polymorphism, encapsulation and so on.

Thanks again.
Quote:Original post by Echkard
C++ is a superset of C.

This isn't strictly true. Rather, C++ was designed with the aim to be compatible with C code, but it's not a perfect compatibility--there are subtle differences. Approaching C++ as if it were C with classes will ultimately lead you astray.

Edit: Here's some material on the subject.
Don't worry about it, I have a lot of experience with both (ranging from Windows drivers to desktop applications). Giving up some features of C++ in order to maintain compatibility won't hurt that much.
Quote:Original post by yckx
Quote:Original post by Echkard
C++ is a superset of C.

This isn't strictly true. Rather, C++ was designed with the aim to be compatible with C code, but it's not a perfect compatibility--there are subtle differences. Approaching C++ as if it were C with classes will ultimately lead you astray.

Edit: Here's some material on the subject.


Here's a more dedicated link, some of you will be shocked: Are You Ready For C99?

Excerpt:

Variadic Macros
void realdprintf (char const *file, int line, char const *fmt, ...); #define dprintf(...) realdprintf(__FILE__, __LINE__, __VA_ARGS__)

(taken from here)

Variable Length Arrays
void foo (int x) {    int frob[x];}


Named Initialization (two years before C#, heh)
typedef struct {    int alpha;    int bravo;} Foo;Foo foo = { .bravo = 1, .alpha = 5 };


"Struct Hack" Support
See this.

And some more.


And to lead "C++ is a superset of C" ad absurdum in a freaking glimpse: You can't use "class" as an identifier for a variable in C++ :D

This topic is closed to new replies.

Advertisement