News for hackers. Stuff that matters.
Re:Linus Torvalds on C++ by captaincrunch on Monday February 27, 2012 @08:12PM (#3641365)
Linus is probably the %1 of people in the world who actually needs to get the performance gain that C has over C++ - as for the rest of us? Probably doesn't matter.
Re:Linus Torvalds on C++ by Game_Ender on Monday February 27, 2012 @08:49PM (#3641445)
> needs to get the performance gain that C has over C++

With RTTI and Exceptions disabled you should be able to get almost identical performance with C and C++. In some cases C++ compiler has additional information that can allow it to produce faster code as well.

Re:Linus Torvalds on C++ by dedward on Monday February 27, 2012 @09:35PM (#3641603)
Yup, and if you avoid using any of the new language constructs like objects and whatnot that C++ brings and basically stick to standard C, maybe using just a bit of C++ sugar here and htere, true.... but at that point you might as well be using C, and the argument is really moot.
Re:Linus Torvalds on C++ by Game_Ender on Monday February 27, 2012 @11:22PM (#3641869)
You are wrong. Those the only two features that incur any performance penalty for just existing, and even then it's implementation dependent and in some cases can be zero (ie. zero cost exceptions). Other things that are possibly slow, like virtual functions, can be avoided in specific cases when needed. This is similar to many how C projects use structures of functions pointers, for abstraction, but not everywhere (including the Linux kernel).
Re:Linus Torvalds on C++ by cube13 on Monday February 27, 2012 @09:11PM (#3641530)
You also need to not use: STL(most implementations are too slow) Boost or STLPort(namespace and compatability issues if you're not producing executables) Most OO features like inheritance and polymorphism(a lot of that is resolved at runtime, which eats cycles) Function overloading(debatable, since the compiler should resolve the function signatures at compile time)

You're pretty much left with C with namespaces at that point.

Re:Linus Torvalds on C++ by jmccaffrey on Monday February 27, 2012 @09:18PM (#3641550)
C++ actually has some performance advantages over C, especially relating to static polymorphism (qsort v. std::sort)
Re:Linus Torvalds on C++ by aidenn0 on Monday February 27, 2012 @10:34PM (#3641769)
Technically you can do tricks like that with the C preprocessor, though it is a bit ugly and lacks automatic instantiation.
Re:Linus Torvalds on C++ by yannickt on Tuesday February 28, 2012 @01:34AM (#3642159)
It is also not type safe.
Re:Linus Torvalds on C++ by cageface on Tuesday February 28, 2012 @04:17AM (#3642510)
C++ can actually be faster because it doesn't throw away as much type information. A good, typed C++ quicksort implementation, for example, will be faster than a C version using void*.
Re:Linus Torvalds on C++ by cygx on Tuesday February 28, 2012 @05:04AM (#3642622)
One of the reasons for the performance difference is that you can't inline into the libc DLL blob: If you use qsort(), you'll get a lot of overhead from calling the comparison function.

If you use a custom quicksort implementation and put it into the same translation unit as the comparison function (or compile statically and use link-time optimizations with a sufficiently advanced compiler) you can get the same performance out of C.

Re:Linus Torvalds on C++ by cageface on Tuesday February 28, 2012 @05:43AM (#3642685)
Function call overhead is only one of the issues with the C version based on void pointers.

Check out Stroustrup's keynote at Going Native 2012 for more details: http://channel9.msdn.com/Events/GoingNative/GoingNative-2012...