GCC Moving To Use C++ Instead of C
An anonymous reader writes "CodeSourcery's Mark Mitchell wrote to the GCC mailing list yesterday reporting that 'the GCC Steering Committee and the FSF have approved the use of C++ in GCC itself. Of course, there's no reason for us to use C++ features just because we can. The goal is a better compiler for users, not a C++ code base for its own sake.' Still undecided is what subset of C++ to use, as many contributors are experts in C, but novices in C++; there is a call for a volunteer to develop the C++ coding standards."
I'm guessing that only the C++ compiler part will be written in C++. Sort of an Ouroborus.
One of the reasons for gcc being in C for so many years is that it was easier to get a bootstrap c compiler running on a given platform to compile the full gcc toolchain, but I would guess that a C++ compiler was not that important to those people anyways, but it still begs the question.. how do you get a C++ compiler working on a platform that doesn't have one?
If you need web hosting, you could do worse than here
AC you got that right! C++ is macro for programmers that don't grok struct and pass by ref
considering he sustained that C++ is utter crap and that is why he didn't use it to develop git.... I just long for his rants... ^_^
I 100% agree. A compiler would benefit very little by being moved to C++. Any "OO" use would be almost exactly single instance, and templates wouldnt be part of the subset they would allow. So what, the stream operators? sigh.
"His name was James Damore."
For this kind of job, C++ really is better than C. One of C++'s goals was to standardise things people were doing in C anyway (eg OOP). The advantage of C++ is that the compiler writes all the boilerplate for you. Not only that, but it does it right every single time. Every line of code you don't write is one that does not have a bug.
The main problem is that it is easy to write a basic C compiler and thereby bootstrap a system. With GCC's cross-compiler abilities, this is less of a problem than it might otherwise be, since bootstrapping can always be done on an exitsing, supported platform.
The other solution is for the GCC developers to open up the middle end (like LLVM has done). This would allow one to relatively easily target the compiler to output C, and even a very simple subset thereof, making the bootstrapping process easy. I appreciate their reasons for not wanting to make this easy: they want to prevent proprietary front ends making a mockery of the GPL. I personally think that in this case, they have gone in the wrong direction, and opening up the middle end would yield far more open, copyleft compiler front ends.
Kind of like FUSE has done for filesystems. Sure, it is easier to write a proprietary filesystem than it has ever been for linux. But it is also vastly easier to write free ones too. The end result is that there are far more Free (tm) and interesting filesystems than there ever were.
So, I think in this case that by making lift harder for developers, they have done a bit more damage than would have been caused by accidently making life easier for proprietary developers.
But, that's my $0.02. And I'll keep supporting GCC, not LLVM because it is GPL. I don't want to see the return of the bad old days of code full of #defines written to work around missing features and bugs in 100 different, bad vendor compilers.
SJW n. One who posts facts.
Maybe they've admitted that 'pride' is holding them back and that being able to use STL (for example) is a greater good than being able to do an initial compile on some obscure microcontroller which has a barely functioning C compiler.
No sig today...
On the other hand ... having the compiler mangle the names for you instead of having to do it manually "MyClassAddFloatAndInt()" might be a win in the long term.
No sig today...
I spent a lot of years developing in C, some time in C++ (w/o using the standard template library) and the last year and a half using C++ with stl. So I think I have a pretty valid basis for comparison, and I'd say that C++ has far more ways to go wrong than C does. With C, you pretty much know what you've got. C++ has a number of subtle, nasty bear traps that can bite you. It's true that if you know what you are doing, you can produce good code & get the job done, but that's true of any language, including assembler.
... The operators < and > were tried, but the meanings "less than" and "greater than" were so firmly implanted in people's minds that the new I/O statements were for all practical purposes unreadable."
Here's a couple of items off the top of my head:
Default assignment operator: All you need to do is add a pointer to your class and suddenly code that you don't see causes a bug. Yes, IF you know about this you can work around it. That's true of anything.
Overloaded operators: I was leafing through the original Stroustrup C++ book and found this paragraph about the stream output operator '<<':
"But why <<?
Well, yes, when people see an operator, they "think" they know what it's doing. It's interesting to me that in this very first case of overloading, Stroustrup ran into this fundamental problem, and had to choose a somewhat obscure operator to get around it.
References: references aren't what most people think of as references. They are pointers with syntactic sugar. Try getting a reference to an element of a vector, and then doing something that causes the vector storage to be reallocation. Voila, you have a "reference" that refers to junk.
All of these aren't impossible problems. They are extra issues, inherent in the language, that you simply don't have in C. I think that C++ has a lot of interesting ideas, it has a lot of power, but ultimately it also has a LOT of problems.
Awesome! Now the compilation process can spend 80% of its time repeatedly linking virtual tables and getting confused over pure virtuals, instead of spending 5% of its time running through the symbol table and 95% compiling. Remember, building i.e. X11 invokes gcc hundreds or thousands of times, once for each C file (and it invokes the C preprocessor too, and all kinds of other shit from the toolchain, once for each included file each time it's included).
Support my political activism on Patreon.
Informative? More like troll. Objective-C didn't include Garbage Collection until 2.0, just released. And GC isn't part of the language anyways it is just an implementation detail of their provided base NSObject. My ObjC runtime for embedded systems uses a very different base object implementation which sacrifices some(but not all as using C++ would) dynamic features for speed and memory savings.
I have never met an OO problem that cannot be solved in C. Objective-C makes it easier. C++ just creates more problems.
Objective-C is fast to compile, simple, 105% C-compatible. IMO, Objective-C should become C1x.
Why, exactly, is using STL a greater good from a compiler side?
For example, a std::vector may become correct more quickly than a home-grown array list because more eyeballs will be looking at it. In addition, its operator [] can be overloaded to provide bounds checking.
Speaking of "syntactic sugar", this link below is a good one. Someone above linked to it. I'll just add a little bit to it here. A reference is a pointer, and anyone who tries to tell you otherwise is a fool. It is there to make things more readable - it is not a copy of an object, and the simplest of exercises in the worst book I've read on the language make that very clear. So I don't know why people think they are anything other than fancy pointers.
And they aren't talking about using the headache inducing C++ code, they are going to use the advantages of C++ to make the code simpler and cleaner. At least according to this guy, and if everyone ignores this guy then it's time to fork it and keep it C. I've been using C for 15 years and C++ with STL for 12 at least, and it is natural for me to use straight C with a few C++ features. I always use 'new' instead of 'malloc' because it's harder to screw up the size calculation. Any time I use memory allocation, I use smart pointers - I don't hack them on later.
And if there is some corollary function call that has to be made with another function call, you have a few options. If one has to be called first all the time, why keep them separate? Well of course it keeps the code clean and simple, and it's harder to introduce bugs in initialize-and-use functions. So you keep both of the functions, most easily as Private members of the class, and then you implement the common usage pattern "initialize and use". Set/Get operators are the same way - the code just sets a property, and doesn't care about all of the activity that's triggered behind the scenes.
They aren't trying to make this a headache, they are trying to make the code simpler. If you let it, C++ keeps you from making the same mistakes that C is ridiculed for such as poor memory management. You can cause other side effects if you use everything the language has, but as someone else explained above, few people have gone through the trouble of learning all of the more arcane features of C++ so it's unlikely. More likely is, someone puts in a crazy overload somewhere and someone else rejects the patch saying it doesn't make sense to do it that way, simple is better.
http://gcc.gnu.org/ml/gcc/2010-05/msg00757.html
ah so many of you don't remember the REALLY early days of linux and having to bootstrap gcc. I don't even really recall the details any longer other than IIRC it took 3 full code compiles which took what felt like forever on old 386 machines with a couple meg of RAM... then building X11 which took about as long. ...then the distros with 20 or 30 floppy images appeared with binary packages... no more hours of waiting to build gcc and X11.
Anyways if you read the email link, you'd see they really only want bits and pieces of C++ since, apparently, most of their contributors aren't familiar with C++. Also if you follow the thread they're still obviously in the very early stages as they're branching out into also of unrelated/unimportant/pedantic nonsense interspersed with healthy doses of common sense.
When I started programming for a paycheck in 1991, there were no viable C++ compilers for the obscure underpowered platform known as the IBM PC.
We switched to using C++ for our applications in 1996, more because of the need for GUI integration than because the language did anything magical for our algorithms.
Oh, and at that time, we suffered about a 50% performance hit, even with "cleaning up" our algorithms moving from a 6 year old unplanned C code base to a freshly planned C++ structure. The performance hit was more or less irrelevant, the old code (had a GUI, but) ran in DOS, the new code ran native in Win95, we needed to be in Win95 - resistance was futile.
I think the gcc can benefit from STL containers and such, not that they don't have solutions for all that already coded in C, but switching to the standard ones will make things a bit easier for non gcc veterans to grok, and they should benefit from massive parallelization more easily if they are using standard libraries instead of retooling their old code base for it.