Path: chuka.playstation.co.uk!scea!greg_labrec@interactive.sony.com From: Nick Porcino Newsgroups: scea.yaroze.freetalk Subject: Re: C versus C++ Date: Thu, 15 Jan 1998 23:49:24 -0800 Organization: SCEA News Server Lines: 42 Message-ID: <34BF10FF.13D7@bc.sympatico.ca> References: <69cmja$7pn1@emeka.playstation.co.uk> <34b9e34f.14105854@news.scea.sony.com> NNTP-Posting-Host: vcta01m01-47.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) Chris is out of town this week. I work with him, so I'll throw in my two cents for what it's worth. One note is that we only hire programmers fluent in C++. As far as efficiency goes, I've taken a sprite rendering routine written in C, hand translated it and optimized it in assembly, then compiled the C code in Metrowerks C and in C++, and found that my routine was the fastest, no surprise, but the C version had almost equivalent performance because the compiler knew a few scheduling tricks I didn't. As for C++, the EXACT SAME CODE was generated. Mind you, I wasn't using any C++ specific language features, although the routine was a member of a class in the C++ version. Some C++ constructs like exception handling can cause extreme performance degradation, depending on the vendor. Metrowerks generates very low overhead exception handling code. Visual C++ OTOH causes an overall 25% code bloat, and at least an overall 25% slow down in generated code. I kid you not. Other problematic C++ features like the freakish amount of construction/destruction that goes on can be avoided if you understand the semantics of const references. If you use a clever memory allocator that doles out objects from an array, and never invokes construction/destruction code, C++ works just fine on consoles because you can avoid the biggest C++ bugaboo - memory fragmentation. I've recompiled the BallTest demo using the Metrowerks C++ compiler and get the same framerate as compiling as a C project. I'm 100% convinced that no matter what anyone says, it is possible to write C++ that executes as quickly as a decent C implementation would. Unfortunately, it took several years for me to get good enough to actually be able to say that. Finally, my recommendation if you're just learning to program, is to learn C so you have a good solid language that you can get great mileage out of, then learn Java to get a good grounding in object oriented techniques, threading, and the like, then learn C++ if you are hoping to work in a shop that specializes in C++. - nick