4 ms·
Firefox was written in C++, and WebKit too (coming from KDE). It could be that C++ is better fit for frameworks, while C for libraries. V8 is also C++, but lot
by malkia 15y ago
Firefox was written in C++, and WebKit too (coming from KDE). It could be that C++ is better fit for frameworks, while C for libraries.
V8 is also C++, but lots of other successfull VM's are written in "C"
I like "C" because it's more limiting, hence I won't see templates overused, or latest trick used (SFINAE). It's also easier for me to read.
Also at binary level things are simpler - here is your function, and it's name, it takes this and this as parameter, and returns this and that, also follows this convetion (stdcall, pascal, fortran, etc.)
With C++ my biggest pain has been name mangling. I'm not sure why this was not standartized. It's actually much better that the name of the function automatically contains what types it can take, which would've been much easier for dynamic binding, but then you have GNU, MSVC and others totally differs on how they mangle the name (and from version to version it changes a lot). Also exception handling (mingw/cygwin/msvc - there is big confusion there, and on binary compability level it's hard to combine one with another).
My last show-stopper for C++ was - on this platform you can' t use this feature. For example on certain game consoles exceptions are not allowed. So you go with longjmp/setjmp, but then this would not unwind the stack and call destructors.
Most of all, I got bitten by a heavily templated math library - it was much faster with optimizations than the one before, but without (debug) it was several times slower than same one before it. Why? Because it was relying on inlining everything, and back then gcc for playstation2 was not really inlining everything, even if it was forced.
So every overloaded operation (matrix by matrix, or matrix by vector) was actually function call.
There is another gotcha - sometimes overloaded C++ operators lose their ability to short-cut. For example overloading && and || would not longer short-cut, and many other gotchas.
Most of all, I can't stand boost - it's just too huge.
But I'm totally fine with C++ the simple way (whatever this is) - best example for me is ZeroMQ lib - it's C++ internally, they limit themselves to not use exceptions, and provide "C" interface by default. This makes it very easy to use from other languages - python, lua, ruby, etc.
- cageface 15y agoYeah sure there are plenty of problems with C++. But I don't think writing in raw C is such a great answer either. What I really want is something in between but no such thing exists.
- malkia 15y agoSame here... There is Vala, but just lazy enough to get into it. My choice right now is Lua + C - for fun & experimentation. I also dabbled with Common Lisp, but haven't touched code in it in months, might get back at it later...
- dlubarov 15y agoOut of curiosity, which consoles don't support C++ exceptions? PS2? I would say it's a deficiency in the kernel rather than a language problem... but an understandable one, because the runtime support is tricky (see http://sourcery.mentor.com/public/cxx-abi/abi-eh.html http://sourcery.mentor.com/public/cxx-abi/abi-eh.html). You're right, a standardized mangling scheme would have been nice... but there's always 'extern "C"' if you need a C++ function from asm or a linker script. Compilers really should short-circuit &&/||... were you using some kind of experimental compiler?