5 ms·
C++ has about as much to do with C as Java with JavaScript these days though. It's just not an option in many cases where C is fine. I've gone back and forth th
by sifoobar 8y ago
C++ has about as much to do with C as Java with JavaScript these days though. It's just not an option in many cases where C is fine. I've gone back and forth the last 20 years or so, and have plenty of experience with both languages. Even the experts are beginning to loose faith, it's just getting too damn complex. I'll take variants as an example, the hoops people are willing to jump through to get something as basic as unions working properly is just insane. It looks more like religion than programming from here, Rust has the same cult like behaviors going on all over the place.
Edit: Ah, I see; you're more worried about them turning C into the next C++ :) I might even agree some days.
- gpderetta 8y agoPlease, C and C++ share a large subset, and, most importantly a memory model. Java and JS share, what, a couple of parentheses?
- stochastic_monk 8y agoMost C is inducted into C++ eventually. The point is that it would be nice to have something like RAII without subscribing to the full C++ perspective.
- jcelerier 8y agowell, compile with a C++ compiler and just use RAII ?
- sifoobar 8y agoIt's not that easy. A modern C++ compiler will have all sorts of issues with fundamental C idioms, and depending on C++ is a very different story from depending on C.
- kazinator 8y agoC++ compilers do not have issues with fundamental C idioms. I maintain a significant body of code which compiles as C or C++. The executable size and performance are about the same. A C++ compiler will, of course, have "issues" with C99 and C11 features, that's for sure.
- kevin_thibedeau 8y agoRunning without exceptions is one C idiom. RAII, operator-new, and many other C++ features break down without them.
- kazinator 8y agoObviously, I do not use RAII, operator new or exceptions in a code base that compiles as C or C++. Here let me note that I have not gone out of the way to disable anything in C++. I have not disabled EH in the compiler, or RTTI or anything. Yet, the executable size is close to the C one, and the performance is basically the same.
- jcelerier 8y ago> Running without exceptions is one C idiom well, did you know that for instance the windows C library was implemented in C++ ? and yet we don't see it throwing exceptions left and right.
- danem 8y agoWhich idioms are you referring to?
- sifoobar 8y agoAutomatic void casts, flexible struct fields and calculating offsets to find the containing struct given a field are three that I use all the time. Last time I checked, C++ wasn't very impressed by either one.
- 8y ago
- sifoobar 8y agoSure, the interop is unmatched. What they don't share is mindset; C is all about keeping it simple, I don't even know what C++ is about any more, but it sure isn't simple. Many fundamental tricks that are routinely pulled in C require jumping through plenty of hoops to keep a modern C++ compiler happy. Speaking of interop, calling into C from other languages is very different from calling into C++. Yes, you can write C wrappers, but it's rarely done. And the further the language drifts into template lala land, the more tricky it gets.
- kazinator 8y ago> Many fundamental tricks that are routinely pulled in C require jumping through plenty of hoops to keep a modern C++ compiler happy. Not in my experience. Currently my man open source project consists of some 70,000 of C which compiles as C++. Maintaining C++ compatibility takes very little effort. I tend to switch to C++ before a release, to catch regressions. Often there is nothing. The most I spend is maybe five to ten minutes fixing some minor things. Some of those minor things have nothing to do with C versus C++ like signed/unsigned warnings. Note that these signed/unsigned warnings from GNU C++ actually found a real problem: I had code which assumed WEOF was negative. (It was originally char based code that was switched to wchar_t; of course EOF constant in the narrow character world is negative.) The GNU C++ compiler also identified the situation in the same code that a variable that should have been wint_t was mistakenly int.
- sifoobar 8y agoI'll repeat this here. Automatic void casts, flexible struct fields and calculating offsets to find the containing struct given a field are three things that I use all the time in C. Last time I checked, C++ wasn't very impressed by either one.
- monocasa 8y agoAs someone who's been paid in the past to write shellcode, stuff like that paid my bills.