Re: C vs C++ (was Re: Ports)

From: Chris Gilbert (
Date: 09/10/00

Patrick Dughi wrote:
>         As for the C vs. C++ issues, generally speaking, C programs are
> more optimal than their correctly made C++ counterparts.  That is, if you
> compare and correctly weight speed, program size, memory usage, etc, C
> comes out on top more often.  Some of it's simply because C is not as
> complex as C++;  C++ has to validate at run-time the arguments to
> functions, since you can not only overload operators, but also provide
> virtual(and then overloaded) functions, etc..

Overloading happens at compile time, it looks for the matching function
and uses it.  Virtual functions use a table that is associtated with a
the class, this points to the correct function to call for any required
virtual function.  This is all hidden within the compiler/linker by
using name mangling to give each function a different signature.  The
arguement that a program is slower is not always true.  If you do the
C++ right, you'll have a lot of stuff that gets inlined (all your
accessors should get inlined)  As compilers have improved for C++ it is
capable of hitting the same sort of speeds as C.  In fact using some of
the cunning mechanisms like passing values in by reference should help
speed things up.  The compiler can see what's being done and optimise
it.  (by reference is for when you need to alter the incoming argument,
it's a bit like having an arg of int * if you need to alter the value).
Note that you could do virutal functions by using a table of functions,
and then based on the data you use the fuction from that structure, see
the save_types table in genolc.c (if you're using oasis 2)  The virutal
functions hide this from you, and make it less error prone.

Most of the commercial gaming world uses C++, so it's not all bloat.
Even Play station games are written in C++ (and that's only got 2MB of

At the end of the day it's what features you use of the language that
determine how horrific it is.  C++ allows you to shoot yourself in the
foot, but so does C, you mess up your pointers and it all goes boom, not
matter what language it is.

I have been told that it's C programmers that find C++ hardest to learn
as they're too use to doing tricks etc that in C++ there are other ways
to do.

>         Basically, C++ makes it harder for the computer, by making it
> easier for a programmer to write extensible/etc code.

>         I don't think that a program has to be in C++ to make it good,
> though it may make it easier for medicore programmers to alter without
> cutting their own throats.  As far as I've seen, most C++ code ends up
> being a bit more sloppy, maybe because the programmer never had to force
> themselves to be origanized in another language, like C.

It's a matter of programmer ability, if a programmer does a bit of
design first then things work a lot better, but then that's true for any

>         Of course, that's my opinion, and entirely subjective.

Chuckle, all opinions are subjective ;)

My feeling on all this is if maintenance of code in C++ is easier than
in a c version of the mud I'm happier, I don't want to have to worry too
much that I've just added another 12 affects, and doh I've hit the 32bit
barrier, I want to just use the bitset template and not have to worry
about it (although if I did it in a properly designed way I'd not have a

I like the concept of having an abstract editor that you define an
interface for, and then you just call those functions.  by using virtual
functions they route to the correct place, no more huge case statment in
do_oasis, and you don't spend hours sorting out the interaction of the
case and ifs for things like aedit, hedit and other no-standard editors
(by that I mean those that don't work on vnums)

In reality it all comes down to good/bad design.

OBcircle:  (since most of the rest of this isn't really, it's more
There a few circles that do/did use C++:
deathgate's mud was done in C++, that's where dg scripts came from.  if
you look at how it did some stuff originally it was a lot neater if one
or two places than the C version.
leximud  (runs aliens v predetors) is also done in C++, this is a
derivative of Circle.

Note they're not great examples as they're part conversions from circle,
so still have lots of C in them.

There are also a few codebases written from scratch in C++, eg scrymud

Anyway each to their own :)


     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  |

This archive was generated by hypermail 2b30 : 04/11/01 PDT