Slashdot Mirror


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."

33 of 546 comments (clear)

  1. I think it's a sign of impending apocalypse by Anonymous Coward · · Score: 2, Insightful

    Either that, or could we be about to see the beginning of a gcc/llvm compiler arms race?

  2. Re:Seems odd... by Capena · · Score: 5, Insightful

    how do you get a C++ compiler working on a platform that doesn't have one

    Why not bootstrap using a cross compiler?

  3. Re:C++? by man_of_mr_e · · Score: 3, Insightful

    It's not a horrible language if you take into account it's requirements. C++'s requirements are horrible and make it the monster it is. It has to have all the low-levelness of C with all the high level goodness of a modern OO language. Languages like Java, C#, Ruby, etc.. all have the advantage of not having to be a low-level language as well. While OS's have been written in languages like Pascal (original MacOS for instance and early versions of Windows) those were also largely custom compilers that added low-level functionality to the language.

    So basically, C and C++ are unique in that they are required to be systems languages as well as applications languages. This makes both of them quirky to say the least.

  4. Re:What... by zebslash · · Score: 2, Insightful

    Well, ever thought that issue also happened for a gcc written in C? Compilers come with minimal bootstrap compilers written in assembler to initiate the first compilation. Then compilers compile themselves several times until they reach a final version.

  5. Re:C++? by Anonymous Coward · · Score: 2, Insightful

    Oh, it's got its pros and cons, just like any language. At least with C++, you can point at any given piece of the language, and whether or not you like that piece, understand why it was designed that way. At least with C++, there are rational explanations for why it is the way it is. If C++ is the worst thing you've ever used then I strongly suggest trying to do something nontrivial in AppleScript; C++ will seem pretty awesome after that. :)

  6. Choices, choices by Cee · · Score: 4, Insightful

    To paraphrase Einstein:

    Make things as simple as possible, but not simpler.

    IMHO, one should use as high level language as possible, but not higher. One should never choose a lower level language than necessary only because it is hard core, the choice has to be based on something more substantial.

    I've met several C programmers having the knee-jerk reaction when they hear the word C++ that it's bloated and slow and hard. And tell me what, they haven't read Stroustrup's FAQ lately. C++ can be very lean and mean indeed. As can C# (which I'm mostly using right now).

    1. Re:Choices, choices by daid303 · · Score: 4, Insightful

      If you want to link to any FAQ, don't forget the FQA about C++ http://yosefk.com/c++fqa/

      Reading it will give you an inside on the many issues you can have with C++. I don't oppose C++, but You Have To Know What You Are Doing (TM). Or else all hell breaks lose. Fixing bad C is doable, fixing bad C++ is the 7th circle of hell.

    2. Re:Choices, choices by serviscope_minor · · Score: 5, Insightful

      The C++ FQA is mostly a bunch of rhetoric and sophistry with a good scattering of half-truths thrown in for good measure. It is a classic propaganda piece as the falsehoods are spread very continuously spread and mixed with truthful pieces. That makes it hard to debunk in a short post as one has to go in to nit-picking detail in order to expose it for the hokum that it really is. Fortunately, you can use your favourite search engine to search tha annals of comp.langg.c++.moderated for such information.

      --
      SJW n. One who posts facts.
    3. Re:Choices, choices by TheThiefMaster · · Score: 2, Insightful

      They have a few good points though. On the iostream vs printf issue, they're right that printing formatted output with iostream is stupidly verbose.
      The following are indeed equivalent (actually, the stream version seems to be missing either "0x" or std::showbase)
      printf("0x%08x\n", x);
      std::cout std::hex std::setfill('0') std::setw(8) x std::dec std::endl;

      I'd much prefer it if it was:
      using namespace std;
      cout fixwidth(hex(x), 8, '0') endl;
      which is nearly as short as the printf line.

  7. Re:Seems odd... by Joce640k · · Score: 2, Insightful

    Thinking even harder ... they could compile GCC on another machine but set the output target as the platform they're trying to get it to run on. Then you just copy the binary across.

    --
    No sig today...
  8. Re:C++? by jandersen · · Score: 4, Insightful

    C++'s requirements are horrible and make it the monster it is

    I don't think you are right there. I used to be very sceptical about C++, but I have had to develop some tools with it recently, and my respect for it has grown a good deal.

    It is true that C++ programs can be real horrors to maintain and even to write, but I think the problem often lies with the design of the toolset used. That and the fact that C++ operates on a higher level of abstraction and therefore requires much more careful consideration and planning. The problems I have seen in the past have all been centered around people not quite understanding the nature of C++ and wanting to immediately put all those bright new features to "good" use, by overloading everything and indiscriminately inheriting from any number of classes.

    The secret to good programming has always been to keep it simple - this is twice as important in C++, and the language has some great features for doing so, but you really have to understand what it is you are trying to achieve.

  9. Since they're clearly stealing ideas from clang... by nitehorse · · Score: 2, Insightful

    Maybe while they're at it, they can add in actually-useful error messages. See http://blog.llvm.org/2010/04/amazing-feats-of-clang-error-recovery.html for some examples. It's shocking how user-hostile GCC is in comparison.

  10. Safe subset by steveha · · Score: 5, Insightful

    The GCC guys are not going crazy here. They are discussing what subset of C++ to allow.

    If you use all the wild features of C++, the results could be scary. For example, operator overloading is great if used judiciously, but if used badly it can make the code a mess. And if it is used at all, then it means that you can't look at one page from a printout and know for sure what that code does; you need to look at all the class functions to make sure there aren't tricky overloaded operators.

    I use plain C all the time at work, and the top C++ feature they should be using is simply the object-oriented class stuff. With a single global namespace you need to make functions like MyClassAddFloatAndInt(), but in C++ you could just call that function add(); it would be part of MyClass, and if you have other "add" functions with other type signatures, they won't collide. They could go from:

    {
            MyClass m;
            MyClassInitialize(&m, foo, bar);
            MyClassAddFloatAndInt(&m, 3.0f, 2);
            MyClassDoSomething(&m);
            MyClassCleanup(&m);
    }

    to:

    {
            MyClass m(foo, bar);
            m.add(3.0f, 2);
            m.do_something();
    }

    Even better if they allow the use of C++ namespaces to keep a large project organized.

    The other major win that comes to mind is simply being able to use powerful C++ libraries like the STL. Not having to cook up some kind of container data structure in plain C, but being able to use std::vector<SomeType> and std::map<SomeType, OtherType> and such is a huge win.

    P.S. I read through much of the discussion and here was my favorite post:

    http://gcc.gnu.org/ml/gcc/2010-05/msg00757.html

    steveha

    --
    lf(1): it's like ls(1) but sorts filenames by extension, tersely
  11. thus a disaster by r00t · · Score: 5, Insightful

    That and the fact that C++ operates on a higher level of abstraction and therefore requires much more careful consideration and planning.

    Planning... so you plan, then write, and you are done? This is a project that is expected to live for decades. The requirements change.

    If you need more planning, that's a bad sign.

    The problems I have seen in the past have all been centered around people not quite understanding the nature of C++ and wanting to immediately put all those bright new features to "good" use, by overloading everything and indiscriminately inheriting from any number of classes.

    Yes. Expect it to happen, despite any efforts to resist. This is the nature of a project with more than one developer.

    The secret to good programming has always been to keep it simple - this is twice as important in C++, and the language has some great features for doing so, but you really have to understand what it is you are trying to achieve.

    Human brains are not SMP hardware. A group of people working together will not all see the same big picture.

    Nobody on Earth fully understands all of C++. Every C++ programmer knows a subset. My subset is not your subset; it is unique to me as yours is to you. Features I love make you uneasy at best, and your pet features do likewise for me.

    The features sneak in here and there... well I just can't resist because I really NEED my favorite feature! Think of the classic 2-circle Venn diagram for two people's C++ knowledge: you might hope for your project to be that intersection in the middle, but it's going to end up with the big fat union of pet features.

    Really, you can't stop it. Resistance is futile.

    You'll see exceptions, then memory leaks, an attempt to solve it with some kind of braindead "smart" pointer, somebody needs multiple inheritance, some ass overloads the comma operator or () operator, overloading gets sort of ambiguous with differences between the 32-bit and 64-bit builds, Boost gets pulled in with compile times and start-up times going to Hell, people cry for Java-style garbage collection...

  12. so now I can't grep for functions by r00t · · Score: 5, Insightful

    grep MyClassAddFloatAndInt *.c

    grep add *.c

    This totally sucks. Now I need some complicated language-specific search tool that is sure to have fewer options than grep. It's probably not even scriptable, and surely much slower. Why do you want me to suffer?

  13. C, the best sub set of C++ by itsybitsy · · Score: 2, Insightful

    Subject line says it all. C is the best subset of C++ there is or ever will be.

  14. Re:Finally! by bzipitidoo · · Score: 2, Insightful

    Wait, people were doing OOP in C? I didn't get the impression that all the compiler people wanted C++ for the OOP. Maybe all that some want are the little syntax shortcuts and cleanups and relaxations of rules, like '&' in function declarations for pass by reference, not having to typedef structs in order to refer to structs by their bare names, and ability to declare variables in the middle of code blocks, things like that. Maybe they want member functions and polymorphism only to have cleaner syntax for function pointers and not for actual polymorphism, so that if there was a way to do that without dragging in the full suite of OOP features, they'd go that route. They don't want exceptions. Maybe they don't want function overloading, templates, and operator overloading with the fun name mangling all that needs.

    If so, what they should do is create a new standard for C. Call it "C1x". And I certainly wouldn't leave out things just for being new in C++0x as suggested in the article. Extended initializers is just the sort of thing that isn't necessarily OOP and could go into a new C standard. Add a few things too like a triple comparison operator to make a simultaneous comparison? Certainly fits with one of the big themes of C of being close to the architectures, and every architecture I've come across can do that, so why can't C do that?

    --
    Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
  15. Re:Maybe they've grown up a bit by arth1 · · Score: 3, Insightful

    Why, exactly, is using STL a greater good from a compiler side?
    For a C++ user, sure, but the compiler gains nothing from this, AFAICT.
    It's not like using STL makes code faster or less memory hungry, which, second to the algorithms, should be the focus.

    If I were to guess, allowing C++ serves one real purpose: bringing in the large amount of programmers out there that work with C++. Not because their running code is superior, but because they are there.

  16. Re:Finally! by Renegade88 · · Score: 2, Insightful

    I would like to hear explained how a "schmuck writing code" would be worse off in comparison with a compiler that is BSD(like) licensed.

    If you mention the possibility of some terrible corporation forking and making a proprietary version of the compiler, I'll be disappointed. That situation has no impact on the "schmuck".

    By the way, have you ever looked into how difficult it is to actually contribute a bug fix back to GCC? It's such a hindrance (that's putting it mildly) that patches don't get contributed back. I've got quite a few that I could give back myself on GCC and binutils, but I'm not goign to spend 6 months of my time and my employers time (and approval) to jump through absurd and artificial hoops for an FSF project. LLVM does not suffer from this with their implied copyright assignment (and the fact they actually review bug reports and patches). GCC expects the patch provider to constantly ping the group 4-5 times until someone is so tired of the complaints that they actually review the code. Sorry, that's not acceptable.

  17. Re:Virtual functions as mentioned in the link... by Rockoon · · Score: 2, Insightful

    Templates - how will they do STL without templates??? Seems like a big fail to me.

    The only thing STL adds over traditional container libraries is generics. Why does a compiler need generic containers? The only container that isnt easy to implement-as-needed in the STL that I see a compiler needing (and only for efficiency reasons) is an associative array, and that doesnt actually have to be generic at all.

    I would think that it would be far more preferable to (continue to) implement these things specifically for the compiler, and further that people who think that its hard probably shouldn't be involved in the GCC mainline. Perhaps a nice fork for the algorithmically-impaired is in order.

    --
    "His name was James Damore."
  18. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 3, Insightful

    Pride?

    Come on now, let's be fair. They said that boot strapping with only C was the reasoning. If you've ever bootstrapped a compiler or even worked on cross compiling tool chains for a new platform, what they did is huge. There is a reason that GCC is the compiler just about everywhere. you don't have to like it and I'll agree that some of the reuse stuff C++ can provide is potentially huge but it's not pride, it's the desire to be useful.

  19. Re:Finally! by Anonymous Coward · · Score: 2, Insightful

    I think the view in the GCC community is that eventually they'll use all of C++, just judiciously at first. If you look at GCC source code they're already doing many C++ concepts in C like single inheritance, vtables, etc. It's just that those things look like gross hacks in C and are error prone. For example, to have inheritance you have to maintain structs where the first few members are the same so you can cast between them. Having an enum for what type it is, and voila, there's dynamic_cast. Being compiler writers they know how to do all the tricks, it's just a pain to keep doing so when there's a language that formalized all those idioms already.

  20. Not all that slow by Tony · · Score: 2, Insightful

    Objective-C isn't necessarily that slow. Message passing can be about four times slower than C++ method invocation, but once cached, the two are comparable. (SEE here for some interesting stats.)

    In a system as IO-heavy as GCC, your bottlenecks probably won't be your method calls / message passing. And as for being deterministic: why would a compiler have to be deterministic? There are no hard real-time considerations for compilers. Your variation in compile-times will be minimal, even with a non-deterministic GC.

    I think your point 2 (typed) is fairly valid. Part of the reason to move to C++ is to provide a language that is more strongly-typed than C. While the run-time binding of Objective-C makes it a great language for some applications, it does remove some compile-time type checking. (You do get warnings about an object type's ability to process a message, of course, so you don't lose it all.)

    --
    Microsoft is to software what Budweiser is to beer.
  21. Re:From the article it is obvious by Cyberax · · Score: 4, Insightful

    Nope, not a troll.

    Objective-C is poor. For example, the most useful part of C++ are fast typed template containers.

    Objective-C has only pointer containers which are untyped.

    'Const' support? Nope.

    RAII and smart pointers? Nope. Memory management in Objective-C is quite convoluted, btw.

    So almost nothing useful for general-purpose programming. Except maybe for inheritance.

  22. Re:Finally! by trialcode · · Score: 2, Insightful

    Well fuck you too!

    I'm 33, been writing code daily since I was eight, I started doing C++ around 18, really bought into it, and finally gave up and moved on around 28. I've been there and done that. I've seen projects grind to a halt while people are busy painting their multi-paradigm bike sheds.

    There is no anti-C++ dogma here, only sharing of hard won experience.

  23. Re:Crap by Joce640k · · Score: 2, Insightful

    In all the years this has been debated (at least 15), I've yet to see a concrete example where C is faster than C++.

    Not one.

    If C++ was really slower or more bloated you'd think it would be easy to demonstrate, but nooooo. All you ever find is that the person on the other end doesn't know C++.

    --
    No sig today...
  24. Re:Maybe they've grown up a bit by koro666 · · Score: 2, Insightful

    But then, crappy programmers misuse them, not knowing about what is done behind their back, and it becomes slow and bloated code.

    Having to specify everything explicitely makes you aware of the complexity/memory usage of what you are doing.

  25. Re:Seems odd... by tomhudson · · Score: 3, Insightful

    C++ programmers are the best, most experience programmers around,

    c++ programmers who don't know c all that well (and there are LOTS of them - maybe even the majority) are not the best.

  26. Re:The devs don't know C++?? Its a C++ compiler! by Per+Abrahamsen · · Score: 2, Insightful

    Learn the difference between isA and hasA relationships.

  27. Re:Maybe they've grown up a bit by pdusen · · Score: 3, Insightful

    Crappy programmers are crappy whether they lean on the STL or not. Their implementation of pre-existing STL containers and algorithms is bound to be terrible.

  28. Re:Seems odd... by ultranova · · Score: 2, Insightful

    Sometimes generally accepted doesn't make something right. Kind of like the way everyone calls a van dyke beard style a goatee. :-D Just because a lot of folks say it's so, doesn't make it so. ;)

    In the realm of symbolic languages (such as all natural ones), yes it does. The term "van dyke bear style" has no inherent meaning. Neither do the terms "beard" or "goatee", for that matter. That's why languages differ so much from each other, why they evolve over time, and why jargons - domain-specific language extensions - arise.

    Meaning is determined by usage and usage is influenced by meaning.

    --

    Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  29. Re:Maybe they've grown up a bit by ultranova · · Score: 4, Insightful

    But then, crappy programmers misuse them, not knowing about what is done behind their back, and it becomes slow and bloated code.

    This is a compiler we are talking about. I think that we can assume that people who program the program that turns code into machine code must "know their shit", so to say - otherwise the time taken to compile will be the least of the user's problems.

    Besides, having people copy code from a webpage/programming manual doesn't improve things any.

    Having to specify everything explicitely makes you aware of the complexity/memory usage of what you are doing.

    No, they simply memorize magical mantras that, when regurgitated, will do what they want. It's much better to give such people as high-level libraries as possible and let them use those; the more they have to think about optimization, the more likely they are to do something unbelievably stupid.

    Besides, the exact same argument could be used to condemn first OO, then structural programming, then anything that gets compiled, then finally machine code itself as an abstraction over the physical hardware of modern processors.

    --

    Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  30. Re:Maybe they've grown up a bit by tomhudson · · Score: 2, Insightful

    Why not test it yourself? I did, but I've come to realize that the only way for people to actually believe it is to get off their behinds and test it for themselves. Otherwise, it's too easy to dismiss.

    It's the same as everyone who claims java is "almost as fast as c" when in a lot of cases it is piss-poor. Test it.