I'm with Elysia on this. I have worked on C++ projects that are WELL optimized and would be very hard to manage to do with C - one involved emulating the exact behaviour of a chip, where a 5-bit register had to be a 5-bit register. Doing this:
in C and maintaining a 5-bit value would not be nice.Code:int5 x, y; ... x = getsomething(); y = getother(); x += y;
I was asked by one of the senior managers if I thought we could speed it up by using C instead. My answer was "Probably less than 5%, and it would take far longer to achieve that, than it would take to save 5% by optimizing certain parts of the code". I spent several weeks profiling, analyzing the profiles, and improving the performance. One of the biggest gains was to put if-statements around certain logging calls [that normally didn't get output, so we'd check the output limit FIRST, then call the logging function ONLY if there was actually going to be an output. Just "calling a function that would just return" caused a whole lot of overhead].
C++ as such is not slow. It can be written in a way that produces slow and bulky code. Using STL is a choice that often introduces extra code and extra execution time - which is fine if your application is not terribly time critical, where time-to-market is more important, etc. As usual, it's often just a small portion of the code that is really performance criticial, and if necessary, you could always write THAT BIT in Assembler, plain C or whatever you think will give sufficient benefit.
--
Mats
Last edited by matsp; 11-29-2007 at 04:15 AM.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
The benefits in clarity, maintainability, and extendability that C++ offers to your project far outweigh any small performance degradations you may get.
I had really thought this debate was over a long time ago but I keep seeing it time and time again. IMO C++ has proven itself to be fast enough for the performance based applications. Nearly all of the video games at your local store were coded in pure C++. I doubt seriously anyone is still hanging on to their C API's.
I'm finding more often than not the people who make this claim are the same bunch that love to reinvent the wheel.
I'm with you Bubba. There was a time, a long while back, when I thought you couldn't write C++ OS code, but I'm convinced now that it's perfectly possible. It just requires a good steady skill of OOD, and some good thinking [and the latter is definitely needed if you want to do an OS in C too!]
Either that, or the people who have yet to do some serious programming in C++.
And I think, because C++ offers a richer set of functionality to the user, it can be confusing to new users. You definitely need more experience as a C++ programmer than you do as a C programmer, to write and maintain code well. At least, that's my opinion.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
On the other hand, C++ code can be much easier to read than eqalient C code, so it's a good thing.
Depends on who wrote it, I'd say - and that goes for both C and C++. You can write messy code in both languages - in fact, it's probably easier to do in C++ [just look at the examples with virtual functions and default arguments for some ways to obfuscate the code].
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Yes, I just saw how messy it can be - C++ almost as C, when making a game -_-
But I think that with polymorphism, classes and C++ functionality, written properly, the code will become easier to read and maintain rather than hard-to-read C. Of course, if using functions properly, you can write clean C, too, but I do think C++ is a little better in that department.