Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!pasteur!agate!labrea!polya!shap From: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Newsgroups: comp.lang.c++ Subject: Re: C++ : A free lunch ? Message-ID: <4762@polya.Stanford.EDU> Date: 29 Oct 88 05:50:03 GMT References: <4165@tekgvs.GVS.TEK.COM> Reply-To: shap@polya.Stanford.EDU (Jonathan S. Shapiro) Organization: Stanford University Lines: 41 In article <4165@tekgvs.GVS.TEK.COM> jans@tekgvs.GVS.TEK.COM (Jan Steinman) writes: > > >This is typical of those who think of C++ merely as a superset of > C.. I was involved in writing one of the early major applications at AT&T in C++. I know, better than most C++ programmers, just how and where and *why* C++ is different from C. Your points about virtual functions are valid, but it is worth noting that the same functionality in C requires the same mechanism that C++ uses. If you didn't have constructors, you would do the initialization yourself. Similarly for destructors, but you would have poorer locality of control for optimizing that action. If you don't need to use object oriented programming, it makes sense to stick to C - it is at this point more portable (though it doesn't look as though that will be true long). If you do need object oriented programming, the tradeoff between C++ and SmallTalk/Lisp/Eiffel is control versus garbage collection. I can get a lot of performance out of C that I could never get out of any of the others (and I am a more than competent LISP and SmallTalk hacker - that's not the source of the breakdown). On the other hand, there are some times when you really want garbage collection and the ability to be faster and looser about storage management, or you want to let the reachability (i.e. GC) algorithm decide for you when to free storage. C++ is just as fast as C. Anything you want to do in C++ generates code that is no more complicated than the equivalent C code would need to be to do the same job. Griping that virtual functions have run time overhead is irrelevant - so do pointers to functions in C. In fact, as native code compilers become available for C++, it is reasonable to expect that C++ will outperform C because the compiler can take advantage of the "tricks" that are enabled by knowing the differences in semantics and usage between C and C++. Jonathan S. Shapiro AT&T Bell Laboratories