Portability

I have seen that SDL and most games are written in C and I’d like to know
if old C is more portable than C++. Also if using SDL data types is better
than use language types.–
Roger D. Vargas | "Humans have so many emotions, Artoo. And most
VQt Development Team | seem to cause them pain. I do not understand,
http://vqt.sourceforge.net | but I’m glad I have none. And yet – I can’t help
wondering sometimes… what it would be like."
C-3PO, Protocol Droid. Star Wars 2: World of Fire.

I have seen that SDL and most games are written in C and I’d like to know
if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support the
ANSI standard fully, so you should be safe as long as you stick to that.

However, despite the advantages of C++ for advanced OOP, there are quite a few reasons to stick with C, especially for Free/Open Source projects (some pure facts, some common opinions):
* There are more hackers with a thorough knowledge of C.

* C has fewer constructs and thus fewer "low level"
  programming style options. That makes it easier to
  read anyone's C code and understand it.

* The above also makes it harder to break the local style
  and design of a project. Mixing programming styles can
  make the code harder to read and maintain.

* C has less abstraction than C++, which makes it harder
  to misunderstand code that deals with structures/classes
  and custom data types. (No operator overloading, for
  example.)

* It's generally easier to write absolutely terrible C++
  code than it is to write bad C code.

* In C, it's harder to see levels of abstraction that may
  slow down you code. (Ex: Virtual function calls involve
  two pointer indirections, one being a pointer table look-up,
  and you can't even see that on the code! The corresponding
  C construct is a function pointer in a struct, which is
  to spot and keep track of, even without looking at the
  struct definition.)

* OOP doesn't really pay off for a project of a "sane" size
  and complexity. (Note: You *can* use the C++ features for
  other programming styles than OOP.) Most games aren't big
  or complex enough to warrant the use of OOP, and thus,
  don't really need C++.

* You *can* program in an object oriented fashion in C, and
  the level of OO you can achieve that way addresses most of
  the problems that people chose C++ to deal with.

* You can still use a C++ compiler to compile your C code,
  thus taking advantage of the stricter compile time checking
  that C++ compilers do.

* OOP is not "simply better" or "superior" to all other
  programming styles, but it is indeed very useful for some
  things. However, the C++ features are basically designed
  *only* for OOP, while ignoring other programming styles.
  Thus, when you need to use a different style, you might as
  well use C, as C++ would only be able to help you with the
  syntax of some constructs, if even that.

Personally, I used to like C++ a lot, but over time, I’ve begun to feel that
it’s more complicated and awkward to manage than it is helpful. Sure, it’s
possible to write very good looking code in C++, and it’s possible to use the
OO features in a very productive and time saving manner - but it’s also very
easy to totally screw up a project in a way that it’s next to impossible to
clean it up. Careful design is incredibly important to C++ projects, while
the average hacker isn’t very interested in that anspect of programming at
all…

Note: I’m definitely a designer type of person, but I still don’t like C++
very much when it comes to real projects. Go figure…

Also if using SDL data types is better than use language types.

Yes and no.

In general, for best performance, you should use the standard language types,
but DON’T use those in file formats, networking protocols and the like.
That’s what SDL types are for - you know their size, so all you have to worry
about is endian.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:

Careful design is incredibly important to C++ projects, while
the average hacker isn’t very interested in that anspect of programming at
all…

Lack of interest is no excuse! Besides, bad design is bad design, no matter
what [programming] language you express it with.–

Olivier A. Dagenais - Software Architect and Developer

Careful design is incredibly important to C++ projects, while
the average hacker isn’t very interested in that anspect of programming
at all…

Lack of interest is no excuse!

Certainly not, but it’s an unavoidable fact that most Free/Open Source code
is hacked for fun by people who’d rather just hack away and get something
"cool" running. Just look around - there are plenty of poorly designed
projects with no long term plan.

Besides, bad design is bad design, no matter what [programming] language
you express it with.

Yep; it’s just that more complicated languages allows bad design to become
less obvious, and can result in shortcuts being more dangerous.

BTW, I’ve spent the last few years partly keeping one of these examples of
bad C++ coding alive. (It was written by a C++ beginner who wasn’t even
informed of which tasks the program would eventually have to deal with.) I’m
simply going to have to rewrite major parts of it, as the program is about
ten times as complicated as the problem it’s intended to solve…! heh

And yes, I’m claiming that C code would stand a better chance of being
cleaned up and reused, as it generally doesn’t have a broken OO design
integrated into it. C code is more “cut’n’paste friendly”.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 03:28, Olivier Dagenais wrote:

“David Olofson” <david.olofson at reologica.se> wrote in message
news:0102210232480B.03450 at cutangle.reologica.se

I have seen that SDL and most games are written in C and I’d like to
know

if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support
the
ANSI standard fully, so you should be safe as long as you stick to that.

Actually, none of them do. Or are we thinking of different standards?

  • OOP is not “simply better” or “superior” to all other
    programming styles, but it is indeed very useful for some
    things. However, the C++ features are basically designed
    only for OOP, while ignoring other programming styles.
    Thus, when you need to use a different style, you might as
    well use C, as C++ would only be able to help you with the
    syntax of some constructs, if even that.

Most of my C++ code is written in a procedural style. I use C++ because it
puts more (ugly, horribly verbose, badly designed, but still useful) tools
in my toolbox. There are cases where I find that I’m glad I have virtual
function and templates.> On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:


Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

“David Olofson” <david.olofson at reologica.se> wrote in message
news:0102210232480B.03450 at cutangle.reologica.se

I have seen that SDL and most games are written in C and I’d like to

know

if old C is more portable than C++.

C appears to be slightly more portable than C++ in real life, but this
shouldn’t be a significant problem these days. Most C++ compilers support

the

ANSI standard fully, so you should be safe as long as you stick to that.

Actually, none of them do. Or are we thinking of different standards?

Uhm, no; it’s just me being generally sloppy. :slight_smile:

Right, no compiler seems to support the full ANSI C++ standard, but the
vast majority supports the features that most C++ programmers use. AFAIK, the
likelihood of hitting something unsupported is approaching a level where C++
could be called portable.

Not, truly there yet, though, at least not in theory. I don’t have enough
experience in porting sufficiently modern C++ code around that I can say
whether you can actually rely on it or not.

  • OOP is not “simply better” or “superior” to all other
    programming styles, but it is indeed very useful for some
    things. However, the C++ features are basically designed
    only for OOP, while ignoring other programming styles.
    Thus, when you need to use a different style, you might as
    well use C, as C++ would only be able to help you with the
    syntax of some constructs, if even that.

Most of my C++ code is written in a procedural style. I use C++ because it
puts more (ugly, horribly verbose, badly designed, but still useful) tools
in my toolbox.

Actually, I think some of the tools are pretty nice; I never said C is the
ultimate language. :slight_smile: (Actually, I think C is rather crappy for anything but
low level system code and tight, CPU intensive stuff. Still fitts amazingly
well in a huge range of situations, though; that’s probably why it’s still so
popular.)

The tools may be badly designed in the sense that they’re easy to abuse,
though… (That’s basically what I’m raving on about in about half of that
post.)

There are cases where I find that I’m glad I have virtual
function and templates.

Yeah. There are times when I miss them… But that’s not enough to make me
"break" the C code and turn it into some “C+” language. (Hey, how about
specing that up officially!? :wink: I need more motivation than code syntax to
go there.

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 05:03, Rainer Deyke wrote:

On Tuesday 20 February 2001 22:27, Roger D. Vargas wrote:

No flame wars please! Is just a question.
It’s funny, initially OOP was so obscure for me, but now I can’t think a
solution withouth it. I tryed to design an strategy game a few months ago
to use C structs, when I noticed that SDL was written in C, but I had to
give it up (maybe that time I didn’t knew enough). Now I have been studing
Freecraft source and it is written in C, that have teached me a lot.
Would be interesting to know which language was used to write WarC, StarC
and AOE, and also RPGs like Diablo and Fallout.
What I exactly want to know now is in what cases C++ is “slightly” less
portable than C, because C++ seems to be definitely my choice (I have
dedicated to it a lot of time in the last year).–
Roger D. Vargas | "Humans have so many emotions, Artoo. And most
VQt Development Team | seem to cause them pain. I do not understand,
http://vqt.sourceforge.net | but I’m glad I have none. And yet – I can’t help
wondering sometimes… what it would be like."
C-3PO, Protocol Droid. Star Wars 2: World of Fire.

Karl Fogel in his book “Open Source Development with CVS” mentions this as
well. Most projects tend to start out scratching simple itches, and the project
maintainers most often want a quick solution to their problem at hand.

Luckily, tho, if the project continues, it tends towards better coding style.

I know that in spite of the fact I know better (programming on and off for
nearly 20 years, so there’s no real excuse :wink: I do tend to start out projects
poorly designed and coded. This is because of all the projects I start, usually
only one or two evolve into something that I really need or want.

Case in point (not in C/C++, but Perl), I once wrote these stupid Perl scripts
to run my web-site. I never took them seriously, I was using global variables
everywhere! Later, someone I knew wanted to use them for his site. So I
released them open-source, gave them a name (“Noink”, so I still wasnt taking
them serious!). Now my dumb little scripts have become a suite that’s powering
a few people’s small business Intranets.

If I had known that’s what they would eventually be used for… I certainly
would have taken the project more seriously from the start!

So while it’s not a real excuse, in practicality many projects tends to start
this way.On Tue, 20 Feb 2001, you wrote:

On Wednesday 21 February 2001 03:28, Olivier Dagenais wrote:

Careful design is incredibly important to C++ projects, while
the average hacker isn’t very interested in that anspect of programming
at all…

Lack of interest is no excuse!

Certainly not, but it’s an unavoidable fact that most Free/Open Source code
is hacked for fun by people who’d rather just hack away and get something
"cool" running. Just look around - there are plenty of poorly designed
projects with no long term plan.


Sam “Criswell” Hart <@Sam_Hart> AIM, Yahoo!:
Homepage: http://www.geekcomix.com/snh/
PGP Info: http://www.geekcomix.com/snh/contact/
Advogato: http://advogato.org/person/criswell/

Karl Fogel in his book “Open Source Development with CVS” mentions this as
well. Most projects tend to start out scratching simple itches, and the
project
maintainers most often want a quick solution to their problem at hand.
(…)
So while it’s not a real excuse, in practicality many projects tends to
start
this way.

This is perfectly acceptable for a “proof of concept” prototype. As Eric S.
Raymond points out:

“Or, to put it another way, you often don’t really understand the
problem until after the first time you implement a solution. The
second time, maybe you know enough to do it right.”

He also refers to “plan to throw one (a design or an implementation) away”,
which means forget about that prototype, start over and make it better this
time. This (lack of versionning) seems to be a pretty big obstacle and
that’s understandable: who wants to admit that the previous version wasn’t
so great?–

Olivier A. Dagenais - Software Architect and Developer

David Olofson wrote:

Yeah. There are times when I miss them… But that’s not enough to make me
"break" the C code and turn it into some “C+” language. (Hey, how about
specing that up officially!? :wink: I need more motivation than code syntax to
go there.

Objective C, anyone?

~jeffrey :j

No flame wars please! Is just a question.

Well, that’s kind of hard to avoid when it comes to programming languages and
that sort of stuff… Always too close to home, it seems! :wink:

It’s funny, initially OOP was so obscure for me, but now I can’t think a
solution withouth it. I tryed to design an strategy game a few months ago
to use C structs, when I noticed that SDL was written in C, but I had to
give it up (maybe that time I didn’t knew enough). Now I have been studing
Freecraft source and it is written in C, that have teached me a lot.

To me, OOP is a way of thinking about the relations between data and code,
rather than a way of writing the actual code. However, the underlying design
it does affect the code, and that’s where the language and it’s special
tools come in.

C++ does indeed have a nice set of tools for the constructs that you need for
OO designs, which can make the code cleaner and easier to read.

However, it all becomes machine code eventually, and C is probably the
simplest language that allows you to code virtually any construct that
you could code in asm, while still not being CPU or platform dependant in
anything like the way asm is.

That’s why I like it. I’m a “RISC mind”, I guess; I like small but flexible
tools better than huge sets of more specialized tools.

Still, I am interested in anything that could replace C, fixing some of
it’s flaws, but I don’t think C++ is it, as it’s extensions are strictly OOP
oriented, rather than generic. (Right, I could hack a special set of warnings
or errors into a g++ compiler, and call that “C+” or whatever, but that
probably wouldn’t help the portability situation! heh…)

Would be interesting to know which language was used to write WarC, StarC
and AOE, and also RPGs like Diablo and Fallout.

Don’t know about those games in particular, but I know some games have custom
scripting languages (some compiled or bytecoded) for AI and similar stuff.

There are lots of languages in the world, and many that would be more
suitable for games programming than C or C++, but the majority of them have
one major problem; real time. Garbage colection just won’t work in a huge
real time game. Another big problem is of course finding compilers…

If you don’t want to stick with C, C++ seems to be the best bet WRT all these
issues, IMHO.

What I exactly want to know now is in what cases C++ is “slightly” less
portable than C, because C++ seems to be definitely my choice (I have
dedicated to it a lot of time in the last year).

Well, I guess I’ve been lucky, not having any really serious trouble with
this, but run time type checking is one ANSI standard (proposal?) you won’t
find implemented everywhere, or may find in various mutated forms.

Can’t think of anything else right now; would have to check my reference
litterature and notes. (I’ll probably have a bunch of such notes after
porting a Borland C++/DOS program to gcc/Linux, but that’ll take a while…)

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 14:21, Roger D. Vargas wrote:

Been thinking about it since this thread started, but I haven’t checked it
out carefully enough. Could it be something like what I’m looking for?

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 21:16, Jeffrey Bridge wrote:

David Olofson wrote:

Yeah. There are times when I miss them… But that’s not enough to make
me “break” the C code and turn it into some “C+” language. (Hey, how
about specing that up officially!? :wink: I need more motivation than code
syntax to go there.

Objective C, anyone?

Karl Fogel in his book “Open Source Development with CVS” mentions this
as well. Most projects tend to start out scratching simple itches, and
the project maintainers most often want a quick solution to their
problem at hand.

(…)

So while it’s not a real excuse, in practicality many projects tends to
start this way.

This is perfectly acceptable for a “proof of concept” prototype. As Eric
S. Raymond points out:

“Or, to put it another way, you often don’t really understand the
problem until after the first time you implement a solution. The
second time, maybe you know enough to do it right.”

That’s so incredibly true! Some people have also said (regarding games) that
you should count on throwing all code away and starting over a few times,
if you want a good design that will survive the rest of the development
process. There’s just too much to think of to get more than a fraction of it
right from the start.

He also refers to “plan to throw one (a design or an implementation) away”,
which means forget about that prototype, start over and make it better this
time. This (lack of versionning) seems to be a pretty big obstacle and
that’s understandable: who wants to admit that the previous version wasn’t
so great?

Well, once you’ve really tried throwing a few thousand lines away and
rewrite it all from scratch, I don’t think it will be that hard. It’s
incredible how superior each new version is to the previous one - and that
saves lots of time and frustration later on, when building on the code.

Kind of related to this, I’d just like to mention that if you’re ever
thinking “but this code ain’t gonna’ be extended much, so there’s no point in
designing for it” - forget about it!

Especially in the proprietary world, where you have little time to clean up
and rewrite code, you’ll be forced to add many times as many features as you
could possibly imagine when designing the code. That’s when you wish you
spent a few more hours thinking that design through…

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Wednesday 21 February 2001 18:09, Olivier Dagenais wrote:

This is perfectly acceptable for a “proof of concept” prototype. As Eric
S. Raymond points out:

“Or, to put it another way, you often don’t really understand the
problem until after the first time you implement a solution. The
second time, maybe you know enough to do it right.”

He also refers to “plan to throw one (a design or an implementation)
away”, which means forget about that prototype, start over and make it
better this time.

I believe the original rules were put forward by Frederick Brooks in his
well recommended “The Mythical Man-Month”.

Matt–
/* Matt Slot * Bitwise Operator * http://www.ambrosiasw.com/~fprefect/ *

  • "Did I do something wrong today or has the world always been like this *
  • and I’ve been too wrapped up in myself to notice?" - Arthur Dent/H2G2 */

David Olofson wrote:

Yeah. There are times when I miss them… But that’s not enough to make me
"break" the C code and turn it into some “C+” language. (Hey, how about
specing that up officially!? :wink: I need more motivation than code syntax to
go there.

Objective C, anyone?

Oddly, I haven’t heard of Objective C being used anywhere outside
NeXTSTEP programming. I’ve experimented with this a bit and seems
interesting enough to use, but one always gets the nagging feeling that it
almost, but not quite does the right thing.On Wed, 21 Feb 2001, Jeffrey Bridge wrote:


Rafael R. Sevilla <@Rafael_R_Sevilla> +63 (2) 4342217
UP Diliman Mobile Robotics Laboratory +63 (917) 4458925
OpenPGP Key ID: 0x0E8CE481

Seems to be something it has in common with most languages that figure
various things out at run time rather than at compile time. Dynamic typing is
flexible but dangerous…

Yeah, I surfed around some, and found some info, but it seems to me that
Objective-C approaches the things I consider interesting from the "other"
direction, not quite getting there. It looks like there is some kind of gap
between the high level OO and the mid level “legacy” C - but I may be missing
something.

Anyway, I’m looking for “low level” improvements, like using struct/class
namespaces for member functions, stronger pointer type checking, handy
operators for calling member functions, basic inheritance and that kind of
stuff - not some abstract “engine” that sits in the background trying to
emulate interpretted language behavior with precompiled code… (That sounds
more like a job for MAIA to me, at least for the kind of code I want to wrap
up that way.)

C++ pretty much covers it, and I like the syntax, but I only want o fraction
of it! Preferably one that’s portable, and doesn’t open up too many
interesting ways of screwing up. :slight_smile:

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 22 February 2001 03:31, Rafael R. Sevilla wrote:

On Wed, 21 Feb 2001, Jeffrey Bridge wrote:

David Olofson wrote:

Yeah. There are times when I miss them… But that’s not enough to make
me “break” the C code and turn it into some “C+” language. (Hey, how
about specing that up officially!? :wink: I need more motivation than code
syntax to go there.

Objective C, anyone?

Oddly, I haven’t heard of Objective C being used anywhere outside
NeXTSTEP programming. I’ve experimented with this a bit and seems
interesting enough to use, but one always gets the nagging feeling that it
almost, but not quite does the right thing.

C++ pretty much covers it, and I like the syntax, but I only want o fraction
of it! Preferably one that’s portable, and doesn’t open up too many
interesting ways of screwing up. :slight_smile:

Well, C++ is what you make of it. Exercise self-restraint and you can
write some pretty good portable code. :slight_smile:

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

I’m just a bit worried about how that would work out in a Free/Open
Source project… :slight_smile:

//David

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 22 February 2001 07:13, Sam Lantinga wrote:

C++ pretty much covers it, and I like the syntax, but I only want
o fraction of it! Preferably one that’s portable, and doesn’t
open up too many interesting ways of screwing up. :slight_smile:

Well, C++ is what you make of it. Exercise self-restraint and you
can write some pretty good portable code. :slight_smile:

C++ pretty much covers it, and I like the syntax, but I only want o
fraction
of it! Preferably one that’s portable, and doesn’t open up too many
interesting ways of screwing up. :slight_smile:

well don’t use the the other stuff then, no one forcing you to :slight_smile:

om

----- Original Message -----
From: Sam Lantinga [mailto:slouken@devolution.com]
Sent: Thursday, February 22, 2001 6:14 AM
To: sdl at lokigames.com
Subject: Re: [SDL] Portability

Open Source developer != lazy programmer. Many open source developers
are also professional programmers so their code is just as sloppy as
everyone. I have been a “professional” programmer at several points in
my life, that doesn’t mean sh!t wouldn’t stick to the code I wrote while
I was paid to do it. It was the exact same quality as my normal work,
whether thats good or bad, I wouldn’t care to comment. I’m sure the loki
peeps will agree that “professional” code is often no better or worse
than joe soap code.On Thu, Feb 22, 2001 at 08:04:39AM +0100, David Olofson wrote:

C++ pretty much covers it, and I like the syntax, but I only want
o fraction of it! Preferably one that’s portable, and doesn’t
open up too many interesting ways of screwing up. :slight_smile:

Well, C++ is what you make of it. Exercise self-restraint and you
can write some pretty good portable code. :slight_smile:

I’m just a bit worried about how that would work out in a Free/Open
Source project… :slight_smile:

Martin

Bother, said Pooh as he signed the pact.