Decision C / C++?

Hi Sam !
Again I have a stupid question :slight_smile: I am just asking myself, why you
decided to program SDL in C, instead of C++. Wouldn’t it be more
comfortable using classes on SDL_Surfaces ?
Was it a decision caused by outer demands, personal preferences or
performance ?

Thx for the answer,

Sascha

Sascha G?nther wrote:

Hi Sam !
Again I have a stupid question :slight_smile: I am just asking myself, why you
decided to program SDL in C, instead of C++. Wouldn’t it be more
comfortable using classes on SDL_Surfaces ?
Was it a decision caused by outer demands, personal preferences or
performance ?

I’m pretty sure the big reason is that C is cleaner, more portable, and
best supported by a majority of platforms. A C++ wrapper would be
trivial to make (I have one for a project I’m playing around with in my
minimal spare time), so its not really a big deal.

Also, using C makes it easier to write bindings for other languages,
such as Python, Perl, or whatever.

Sean Etc.>

Thx for the answer,

Sascha

“Sascha G?nther” <s.guenther at lives.de> wrote in message
news:39B41A9E.9080308 at lives.de…

Hi Sam !
Again I have a stupid question :slight_smile: I am just asking myself, why you
decided to program SDL in C, instead of C++. Wouldn’t it be more
comfortable using classes on SDL_Surfaces ?
Was it a decision caused by outer demands, personal preferences or
performance ?

As a C++ programmer, I prefer the C-style interface.–
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

First, Portability. C is the easiest to compile across platforms, and I
think one of the main motivations for creating SDL is that it would be
cross-platform.

I don’t mean to slam C++: with a lot of work, C++ can be pretty good across
different compilers. It helps to avoid C++ “power tools” like namespaces,
STL, multiple inheritance, inline functions, etc etc etc. It’s tempting to
use these features to make your life easier and get easy speedups, put
portability usually suffers greatly. I would just use C++ for inheritance
and polymorphism, and that’s it.

Second, Performance. C is a little closer to the hardware than C++, so the
compiler can optimize more and generate smaller, faster code.

Third, Preference. Use what you know and are comfortable with.

That last one is a bit of a guess (tried to make 3 P’s :slight_smile: but I think the
first 2 are essential to successful cross-platform development.

Second, Performance. C is a little closer to the hardware than C++, so the
compiler can optimize more and generate smaller, faster code.

This is a myth, you can use all the same tricks in C++ to optimise you inner
loops as in C, but C++ gives more flexibility for higher level stuff.

I agree with your other points though.

jan wrote:

Second, Performance. C is a little closer to the hardware than C++, so the
compiler can optimize more and generate smaller, faster code.

This is a myth, you can use all the same tricks in C++ to optimise you inner
loops as in C, but C++ gives more flexibility for higher level stuff.

I agree with your other points though.

Thanks, I was going to say the same.

C++ is just as performing as C, if not more so, because the compiler is
free to optimize constructs such as virtual tables that are only
implicit in C.

If programmers misuse such constructs, well, that’s not the fault of
C++.

Also, of course, the current state of compiler optimization factors in.
For example, MS has no plans to make VC++ ISO compliant, as evidenced in
their upcoming release (which focuses on C# instead).–
Marc A. Lepage
http://www.antimeta.com/
Minion open source game, RTS game programming, etc.

Normall I am a huge C++ advocate but…

I have to say that C++ looks great on paper and even in theory. I have
used stuff that is supposed to work a certain way many times in C++.

Borland C++ for example had a couple versions of string that do copy on
write and therefore incorrectly modified data that should have been
protected.

Even GNU G++ has an example that breaks the compile.
Its perfectly legal C++ code too. <It puts Visual C++ into an infinite
loop during compilation>

It seems that the complexity of what you can do in C++ is the problem. C
is simple. This makes it easier to implement correctly.

I would have to say that I have yet to see a C++ compiler that does
everything C++ advertises it can do or even behaves the
way it should.

Don’t get me wrong I like C++. I just wish those who wrote the compilers
could get it correct. I realize this is a non-trivial task.

So you see the current state of compilers shows that C is better
implemented everywhere while C++ may not work properly everywhere.

DaveOn Tue, 5 Sep 2000, Marc A. Lepage wrote:

jan wrote:

Second, Performance. C is a little closer to the hardware than C++, so the
compiler can optimize more and generate smaller, faster code.

This is a myth, you can use all the same tricks in C++ to optimise you inner
loops as in C, but C++ gives more flexibility for higher level stuff.

I agree with your other points though.

Thanks, I was going to say the same.

C++ is just as performing as C, if not more so, because the compiler is
free to optimize constructs such as virtual tables that are only
implicit in C.

If programmers misuse such constructs, well, that’s not the fault of
C++.

Also, of course, the current state of compiler optimization factors in.
For example, MS has no plans to make VC++ ISO compliant, as evidenced in
their upcoming release (which focuses on C# instead).

–
Marc A. Lepage
http://www.antimeta.com/
Minion open source game, RTS game programming, etc.

just an url to read an interview from kernighan
http://www.cs.cmu.edu/~mihaib/kernighan-interview/index.html

he talks about c and c++… that won’t help you to choose but it’s nice
to read …–
bozo_fr


Hi, I’m a signature virus. plz set me as your signature and help me
spread
:slight_smile:


Hi Sam !
Again I have a stupid question :slight_smile: I am just asking myself, why you
decided to program SDL in C, instead of C++. Wouldn’t it be more
comfortable using classes on SDL_Surfaces ?
Was it a decision caused by outer demands, personal preferences or
performance ?

In answer to your question, when I started SDL C++ wasn’t completely
implemented or available on many platforms that I wanted SDL to support.
I wanted SDL to run on as many platforms as possible. Since then, I’ve
made SDL work great in C++ code, but the core is still good clean C.

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Except for the standard library, gcc 2.95.2 seems to have everything
to describe. The library can be fixed with libstdc++v3 or stlport. It
has covariant returns, partial specialization, partial specialization
of member templates, and. namespaces Use -fhonor-std if you want it to not
ignore the std:: namespace — unfortunately, this breaks the iostream
library gcc ships with.On Tue, Sep 05, 2000 at 09:31:42AM -0400, Dave wrote:

Don’t get me wrong I like C++. I just wish those who wrote the compilers
could get it correct. I realize this is a non-trivial task.

–
“Isn’t vi that text editor with two modes… one that beeps and one
that corrupts your file?” – Dan Jocabson, on comp.os.linux.advocacy