Sign in to follow this  

Portable game engine - C or C++?

This topic is 2659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Quote:
C++ is a superset of C.
Quote:

Approaching C++ as if it were C with classes will ultimately lead you astray.
That's interesting, as Bjarne Stroustrup -- whom I once met -- said that was exactly his goal when designing C++, to make it "C with Classes". Yes, there are some mostly trivial differences, but I've succesfully compiled many a C project under a C++ compiler with little to no changes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Echkard
Quote:
C++ is a superset of C.
Quote:

Approaching C++ as if it were C with classes will ultimately lead you astray.
That's interesting, as Bjarne Stroustrup -- whom I once met -- said that was exactly his goal when designing C++, to make it "C with Classes". Yes, there are some mostly trivial differences, but I've succesfully compiled many a C project under a C++ compiler with little to no changes.


I would no longer call them trivial as for above mentioned C99 features. And not all C99 features will also be supported in C++0x.

That is not to say, of course, that most C is also C++. But a significant amount is not.

Share this post


Link to post
Share on other sites
I think C++ 0x has a quite a long road before it will be approved, because i think they had 2010 as a deadline and they didn't make it.

Btw, how about SIMD support on mobile processors?

Share this post


Link to post
Share on other sites
Quote:
Original post by Echkard
Quote:
C++ is a superset of C.
Quote:

Approaching C++ as if it were C with classes will ultimately lead you astray.
That's interesting, as Bjarne Stroustrup -- whom I once met -- said that was exactly his goal when designing C++, to make it "C with Classes". Yes, there are some mostly trivial differences, but I've succesfully compiled many a C project under a C++ compiler with little to no changes.


Funny how years and years of language development and learning can change an outdated original goal, isn't it? I don't think he would consider C++ "C with Classes" today, and indeed, he spends a lot of time trying to explain to educators that C++ is its own language and needs to be taught differently than learning C features and then C++ features.

Learning Standard C++ As A New Language

Share this post


Link to post
Share on other sites
Quote:
Original post by meeshoo
I think C++ 0x has a quite a long road before it will be approved, because i think they had 2010 as a deadline and they didn't make it.


As I understand it, the deadline is March 2011. Mind you some compilers already support it.

Quote:
Original post by meeshoo
Btw, how about SIMD support on mobile processors?


This has got nothing to do with C++, and everything to do with the CPU manufacturers.

Share this post


Link to post
Share on other sites
I know it hasn't have anything to do with C++, but still it is about portability, and I know too little about what kind of CPUs are on the majority of the phones. I know ARM architecture is very popular, but are there any others that I should care about?

Share this post


Link to post
Share on other sites

This topic is 2659 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this