Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Nick Newsgroups: scea.yaroze.freetalk Subject: Re: C versus C++ Date: Wed, 21 Jan 1998 22:37:36 -0800 Organization: SCEA News Server Lines: 74 Message-ID: <34C6E92E.1D33@bc.sympatico.ca> References: <69cmja$7pn1@emeka.playstation.co.uk> <34b9e34f.14105854@news.scea.sony.com> <34BF10FF.13D7@bc.sympatico.ca> <34C293DF.6237DFF6@forefront.com.au> Reply-To: Nick_Porcino@studio.disney.com NNTP-Posting-Host: vcta01m06-173.bctel.ca Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 3.01-C-SYMPA (Macintosh; I; PPC) Toby wrote: >How does [Metrowerks] compared to the code generated by GCC? >Current wisdom seems to be that the GCC codegen is really rather >tight. My understanding is that Metrowerks isn't as tight as GCC, although a REALLY interesting point which you can glean if you read Metrowerk's annual report is that Metrowerks is donating work to the gcc project, specifically updating the compilers to support ELF format and there might be some compiler technology cross over as well. I've noticed that gcc and Metrowerks share some of the same quirks (read "bugs") which I wouldn't want to read TOO much in to. >The identical code generation is pretty normal. Essentially if you >use C++ as nothing but C with classes, then you can expect that, ... Well put. >* virtual methods > These both increase the size and ctor code length of structures, > as well as force all method calls to go through an extra table > lookup. We only use pure virtual methods in game code, and we only did that after we verified that pure virtual base classes do not generate vtables under VC++ or Metrowerks. The reason we use pure virtuals is to enforce an interface. Something you can nowadays use templates for in some cases. >* passing classes by value > This is an extension of the const problem. I'm pretty sure that the > compiler can't optimise away const pass-by-value, as that requires > making an assumption that the copy ctor doesn't have side-effects. > If that's the case, then passing by value will cause much more > code execution. Passing by const reference is much more preferable. Danger danger Will Robinson! Passing by const reference has a REALLY EVIL side effect - the compiler will generate temp references galore! In a recent game engine, we did a lot of const String& parameter passing and discovered that VC++ and Metrowerks both generated hundreds of thousands of copies of the string objects at run time just to make sure nothing icky happened! This is the biggest C++ gotcha of all time, I think. P-YEW! We've banned const Object& parameters since then. >* templates > Templates are evil. 'Nuff said. While they're kind of handy in some > places, when memory is a premium, they're really nasty. They do have their place, but you really have to know what you're doing. After the const ref fiasco, I'm doubly careful about static members in templates, especially. [...] >One thing that must be said though, is that to write C++ for speed is >often to write C++ like a C programmer, which in some ways defeats the >purpose of OO programming. I didn't properly learn the distinction until >I came back to OO programming via another language entirely. I've started thinking of C++ as a souped up C, and am backing down on a lot of supposedly good practices, like accessor methods. [...] >To throw in another opinion here, Python is easily as good a language as >Java, in terms of learning Object Oriented programming.... A lot of guys in our shop swear by Python. Thanks for your thoughtful comments, - nick