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

86 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. Seems odd... by man_of_mr_e · · Score: 2, Interesting

    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?

    1. 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?

    2. 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...
    3. Re:Seems odd... by Anonymous Coward · · Score: 5, Funny

      now I'd like to see the graph of what was used to compile each compiler, until the first one written at hand on perforated cards, programmed for abacus in the classical ages

    4. Re:Seems odd... by Philip_the_physicist · · Score: 3, Interesting

      If they used an early enough variant of C++, they would be relatively straightforward, since that has already been done once (cfront), but templates would probably make things somewhat harder, and would probably require a decent macro language. If they want some of teh nicer-sounding features of C++0a, things might start getting very horrible quite quickly.

    5. Re:Seems odd... by FlyingBishop · · Score: 5, Funny

      With the nodes that insert a backdoor into the unix login program colored red.

    6. Re:Seems odd... by mog007 · · Score: 4, Informative

      At best, the compiler would date back to Grace Hopper, as she was the person who invented the compiler. I believe it was for Fortran.

    7. Re:Seems odd... by Per+Wigren · · Score: 5, Informative

      It was Flow-Matic aka B-0 which later kind of evolved into COBOL, also designed by her.

      --
      My other account has a 3-digit UID.
    8. Re:Seems odd... by ommerson · · Score: 2, Informative

      C++ compilers have been implemented this way in the past, but it's a far from optimal approach for for modern C++ - hence why nobody does it any more.

    9. Re:Seems odd... by ixache · · Score: 2, Funny

      So you're saying that this "Grace Hopper" character, far from being the role model for (female) programmers that the official history posits, was actually a spawn of the devil, the mother of the business programming scourge?

      And by the way, what kind of name is "Grace Hopper"? A thinly veiled reference to the Plague of Locusts, I tell you! Isn't that definitive proof? Brace yourself, Jiminy!

      --
      Do I make sense? Please report if not.
    10. Re:Seems odd... by siride · · Score: 2, Informative

      What you said is true of any language. More apropos of the subject, it's not that simple: http://languagelog.ldc.upenn.edu/nll/?p=2290

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

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

    13. Re:Seems odd... by nacturation · · Score: 5, Funny

      The English language, being the whore that it is, pretty much allows you to make any word or phrase mean anything over time, as long as you use the generally accepted meaning at the time.

      For all intensive purposes, I could care less.

      --
      Want to improve your Karma? Instead of "Post Anonymously", try the "Post Humously" option.
  3. Great by jimmydevice · · Score: 2, Funny

    We have to pick through the preprocessor output to find the broken bits.

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

  5. Re:What... by Ckwop · · Score: 3, Informative

    How do you compile a compiler written in the language it compiles...

    Enjoy

  6. Out of the ashes and into C++ by trialcode · · Score: 4, Funny

    Great idea! This will surely help steal back users from LLVM/clang. The reason people are jumping ship is because they want a compiler written in C++, it has nothing to do with performance, licenses and/or features. Just thinking about those crunchy templates, page up and page down, makes my mouth water. I can't even begin to comprehend how they ever got anything done without templates.

    1. Re:Out of the ashes and into C++ by larry+bagina · · Score: 3, Informative

      LLVM is a virtual machine, optimizer, and compiler infrastructure, not a compiler itself. Clang is written in c++ and support C, Objective C, and C++ (c++ support isn't complete but it self compiles and can compile boost and their own stl). gcc-llvm is a fork of gcc that uses llvm for the code generation. There's also dragonegg, which is a plugin for newer versions of gcc to use llvm code generation without any gcc modifications (well, I think there's a small patch involved). Side note, it's curious how they finally allowed plugins.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

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

  8. 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. :)

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

    4. Re:Choices, choices by murdocj · · Score: 5, Interesting

      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.

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

      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.

    5. Re:Choices, choices by b4dc0d3r · · Score: 2, Interesting

      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

      I think we've decided to switch, but we haven't decided to what subset of C++ we're switching. I think that we want what might be called the "syntactic sugar" subset. For example, single inheritance to replace our C-style inheritance, constructors/destructors to replace explicit calls to required initialization/finalization functions, and member functions to implement ADTs, namespaces to save us some typing.

    6. Re:Choices, choices by binarylarry · · Score: 2, Informative

      Actually you have it almost completely backwards.

      A program like "Hello World" with be much, much faster in C than any of the Java derivatives like C#. A language that has a runtime requiring an expensive initial malloc for it's generational GC and a lot of fancy class/assembly loading will be an order of magnitude slower.

      However a long running application is where the language's JIT features really shine, as they're able to optimize and reoptimize whereas a statically compiled language cannot. This is where you hear about "java faster than C++" simply because Java is dynamically compiled and C++ is statically compiled. C# has similar abilities.

      --
      Mod me down, my New Earth Global Warmingist friends!
    7. Re:Choices, choices by binarylarry · · Score: 2, Informative

      Actually there is, it's called array bounds checks removal and escape analysis. ;)

      --
      Mod me down, my New Earth Global Warmingist friends!
  10. Incorrect headline by Letharion · · Score: 5, Informative

    The headline says "Use C++ instead of C" which is incorrect. C++ is, as made obvious from the text, an option, not a requirement.

  11. The devs don't know C++?? Its a C++ compiler! by Viol8 · · Score: 5, Funny

    Are they seriously trying to suggest that the people who work on developing and maintaining a C++ compiler are novices in C++??

    Sorry , am I missing something here?

    1. Re:The devs don't know C++?? Its a C++ compiler! by chocapix · · Score: 5, Informative

      I think you're confused. Strictly speaking, GCC isn't even a C compiler.

      GCC stands for "GNU Compiler Collection". In that collection, there's a C compiler as well as a C++ compiler, a Java compiler, and many more (they are not completely separate, they actually share a lot of code between them). All of them are written in C, and the news here is they're going to be written in C++ in the near future.

    2. Re:The devs don't know C++?? Its a C++ compiler! by dgriff · · Score: 5, Funny

      Are they seriously trying to suggest that the people who work on developing and maintaining a C++ compiler are novices in C++??

      Car analogy time! You can be an expert car mechanic without knowing how to drive.

      I'll get me coat...

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

      The Ada front end is written in Ada.
       

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

  12. Re:What... by Anonymous Coward · · Score: 2, Informative

    No, they don't. That's how they did it back when the first compilers were made. Now everybody just uses an existing compiler, or in case there isn't one, cross-compiles on another system. And if you aren't a compiler developer, you simply download a precompiled binary of the compiler you want, or purchase an installation disc with the binary.

  13. Great ! Another printout to burn by abies · · Score: 2, Funny

    Looking at the GNU Coding Standard which is used for gcc, whatever 'best practices' and style guideline they come with will make a good fireplace material ...

  14. Finally! by serviscope_minor · · Score: 2, Interesting

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

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

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

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

  16. C++ flame wars by o'reor · · Score: 5, Funny
    starting in 3... 2... 1...

    Here's somme ammo from bash.org:

    Phil: C++ is java's uncle that never comes to visit, and had half his face blown off when he stepped on a landmine, also he's a pedophile.
    Phil: But he's the industry standard.
    David: and runs much faster
    Phil: He has to be able to run fast, he's a pedophile.

    --
    In Soviet Russia, our new overlords are belong to all your base.
  17. 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.

  18. 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
    1. Re:Safe subset by Joce640k · · Score: 2, Interesting

      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...
  19. Re:What... by josgeluk · · Score: 5, Funny

    Quis compilabit ipsos compilatores?

    ecco, tibi fixi .

  20. Re:From the article it is obvious by Cyberax · · Score: 4, Informative

    Because ObjectiveC is a slow shit?

    Seriously, it might be OK for designing GUI interfaces, its dynamic nature helps there. But for compiler writing I'd prefer something:
    1) Fast.
    2) Typed.
    3) Deterministic (no non-deterministic GC).

  21. Maybe they've grown up a bit by Joce640k · · Score: 2, Interesting

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

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

    3. Re:Maybe they've grown up a bit by ommerson · · Score: 5, Informative

      Quite simply because STL is the embodiment of several decades of algorithms and data structures research work. In many cases, use of STL results in near optimal code. In raw C, you're left to yourself to write your own collections and algorithms. You have to try pretty hard to surpass the performance of STL. Do you want compiler developers to constantly reinventing wheels or actually improving the compiler?

    4. Re:Maybe they've grown up a bit by Eponymous+Coward · · Score: 4, Interesting

      It's not like using STL makes code faster or less memory hungry

      Sometimes it does. For example, compare the stl sort routine with qsort. The stl version is declared with a predicate method that can be made inline. The C version is passed a pointer to a predicate function that can't be inlined. So, the C++ version can eliminate a function call with each compare.

      But this is library and compiler dependent. In theory you really need to know how your compiler and library perform. In practice, it's so mature that everybody is pretty fast these days.

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

    6. Re:Maybe they've grown up a bit by tomhudson · · Score: 3, Interesting

      Quite simply because STL is the embodiment of several decades of algorithms and data structures research work. In many cases, use of STL results in near optimal code. In raw C, you're left to yourself to write your own collections and algorithms. You have to try pretty hard to surpass the performance of STL. Do you want compiler developers to constantly reinventing wheels or actually improving the compiler?

      Since this is Troll Tuesday I'll be blunt - that's absolute horsheshit!

      In testing, performance can be 4x SLOWER with the stl than by using c99. Variable-length arrays combined with bsearch make for one of the fastest look-up "containers" going - way faster than any stl algorithm.

      c++ has its uses. It has nice features. The stl, on the other hand, is visually offensive. I bought the hardcover TR1 spec, read it twice, and consider it a waste of time and money. For what most people need, if they can't write their own classes, there's enough generic code that they can modify to achieve their goals.

      On top of which, object-oriented programming is a paradigm, not a language feature. You can do OOP in c just fine by passing an explicit "this" as the first parameter in any function you want to act like a method call. You can even do OOP in assembler - Borland had some nice material on that.

      Use c++ for encapsulation, for references, for the syntactic sugar - but not because the stl will make it run faster - it won't.

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

      Using STL frees you from having to do manual memory management

      Here, let me fix that for you:

      Using c++ might free you from having to do manual memory management - just make sure you type a free for every malloc, and that your free gets called when the object goes out of scope (usually in the destructor). Then as the stack pointer gets unwound, the destructor calls your free.

      Have an explicit contract with any other objects or code that uses data this object has allocated - which you should be doing anyway or your code will be thrown out by the next person who has to maintain it.

    8. Re:Maybe they've grown up a bit by MadKeithV · · Score: 2, Interesting

      In testing, performance can be 4x SLOWER with the stl than by using c99. Variable-length arrays combined with bsearch make for one of the fastest look-up "containers" going - way faster than any stl algorithm.

      Care to elaborate on this? I'm a c++-guy, and these VLAs tickle my curiosity. Any idea on what makes the performance difference between the STL algorithms/containers and VLAs? If it's heap allocation, that can be worked around in several ways, but if it's something else well then things just got interesting.

    9. Re:Maybe they've grown up a bit by XDirtypunkX · · Score: 5, Interesting

      Oddly enough, STL contains a bsearch algorithm that works on variable length arrays and generates code which is pretty damn optimal. It also contains a highly optimized quicksort implementation (along with other sorting and inserting algorithms) that you can use to keep your array sorted. However, even the standard vector operations compile down to pretty much raw pointers if you use iterators, so you can use quicksort/bsearch with no extra penalty on a vector and all the work is done for you.

      So it sounds awfully what you're saying is absolute horse-shit.

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

    11. Re:Maybe they've grown up a bit by tomhudson · · Score: 3, Interesting

      variable-length arrays were a surprise to me too. I had been looking for the quickest way to do an in-memory search to find keys so I could look up the associated pointer, and as we all know, c doesn't have variable-length arrays ... but c99 does. Use -std=c99 on the compiler line.

      What this means is that you can treat your chunk of ram as contiguous, and realloc to grow it, and if you try to do an array access past the "old" bound, you no longer throw an exception. So your initial array allocation (in my case, 1024 elements) could grown (again, in my case, to a million) and still work.

      Doing a bsearch on that is dirt quick. Being able to refer to any element, even those beyond the original length, using standard array notation, is just SO nice.

      http://publib.boulder.ibm.com/infocenter/comphelp/v8v101/index.jsp?topic=/com.ibm.xlcpp8a.doc/language/ref/variable_length_arrays.htm

      A variable length array, which is a C99 feature, is an array of automatic storage duration whose length is determined at run time.

      If the size of the array is indicated by * instead of an expression, the variable length array is considered to be of unspecified size. Such arrays are considered complete types, but can only be used in declarations of function prototype scope.

      A variable length array and a pointer to a variable length array are considered variably modified types. Declarations of variably modified types must be at either block scope or function prototype scope. Array objects declared with the extern storage class specifier cannot be of variable length array type. Array objects declared with the static storage class specifier can be a pointer to a variable length array, but not an actual variable length array. The identifiers declared with a variably modified type must be ordinary identifiers and therefore cannot be members of structures or unions. A variable length array cannot be initialized.

      A variable length array can be the operand of a sizeof expression. In this case, the operand is evaluated at run time, and the size is neither an integer constant nor a constant expression, even though the size of each instance of a variable array does not change during its lifetime.

      A variable length array can be used in a typedef expression. The typedef name will have only block scope. The length of the array is fixed when the typedef name is defined, not each time it is used.

      Now don't tell me that isn't sweet! For some algorithms, it's a real game-changer, making them so much simpler to implement - and explain to others - that you never want to go back.

    12. Re:Maybe they've grown up a bit by shutdown+-p+now · · Score: 4, Interesting

      I've not only tested it, I've looked at the disassembly of output that various C++ compilers produce from STL code at maximum optimization settings. In pretty much all cases, the algorithms are very aggressively inlined, with the overhead non-existing. I.e. you'd not do any better by manually implementing a sort or a binary search inline at the same point.

      STL containers are somewhat slower when excessive copying is taking place. This was hard to avoid in the past in some cases - you could use std::swap to optimize manually, but it was not always possible. But C++0x has rvalue references and move semantics now to deal with this, and STL containers use them to greatly optimize things. Furthermore, rvalue references enable perfect forwarding, and that, combined with typesafe vararg functions built on template parameter packs allow C++0x STL containers to provide member functions to instantiate objects directly in-place, without any copying (emplace_back etc).

      And g++ already implements all this, so it's immediately applicable here.

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

    14. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 2, Interesting

      Parent doesn't know what he's talking about.

      In C++ you can have std::vector with std::binary_search, which will be at least as fast as bsearch. The reason -- bsearch calls a comparison function for each stage of the search, but std::binary_search, being a template, can inline the comparison.

      But anyway, normally you wouldn't use them, because such a combination is essentially the same as an overly complicated std::set. The difference is the dynamic allocation, but if it bothers you, you can always give it your own array allocator. And if, for some strange reason, you want to refer to inexistent indexes, std::map::operator[] will allow you to do that, and create a default value under that index when you first access it.

      The STL is convenient, flexible, fast and there is no way anything in C can live up to it.

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

    16. Re:Maybe they've grown up a bit by sim82 · · Score: 3, Interesting

      how true
      I had this funny 'aha' moment doing some simple operations on all elements of an int array: using a stl::vector and an iterator is actually faster than a plain-c int-array indexed by the loop-counter. The stl version boils down to pure pointer arithmetics, while the c version has the indexing overhead. Sure you can do the equivalent in c (as fast as an stl iterator, surprise, surprise), but honestly I like to keep away from this kind of stuff, most of the time.

    17. Re:Maybe they've grown up a bit by HuguesT · · Score: 2

      The STL definitely can make your code run faster. For instance, the standard way to sort an array in C is with quicksort(), which requires a function pointer argument. This function is called for each comparison.

      In C++, with the STL, you would use the sort() algorithm, which is inlined by the compiler. No function call. The resulting code can be an order of magnitude faster !

      Read this report for some code and illustrations. The C++ code is easy to write and in their example still faster than a hand-designed sort routine.

      Finally STL has little to do with OOP, but everything to do with *generic* programming.

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

    1. Re:thus a disaster by MadKeithV · · Score: 5, Informative

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

      If the first thing you get from C++, coming from C, is exceptions, then you're going to be in a world of pain. Most people who started with C++ have trouble with it. For a quick indication why, see Code Complexity @ GOTW.ca .

      As a 10-year veteran of C++, I say to start with RAII, and since you're going OO, require everyone involved to learn the SOLID principles.

  23. Re:80's technology by Narishma · · Score: 5, Funny

    Yeah, exactly. I don't understand why they didn't chose something modern like Ajax.

    --
    Mada mada dane.
  24. 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?

    1. Re:so now I can't grep for functions by Joce640k · · Score: 5, Funny

      Ummm... just right click the function name and select "Find all references" from the popup menu.

      --
      No sig today...
  25. 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.

  26. 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."
  27. Hooray for a slower compiler! by bluefoxlucid · · Score: 2, Interesting

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

  28. Re:What... by Anonymous Coward · · Score: 2, Funny

    is this on topic because it's also in a dead language?

  29. 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.
  30. More eyeballs by tepples · · Score: 3, Interesting

    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.

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

  32. Re:As everyone forgot EGCS vs GCC back in Linux 2. by grub · · Score: 2, Funny


    I have a Caldera OpenLinux T-shirt from back in the day. I still wear it around once a week

    You wear it on those days you want to get laid, eh? :)

    --
    Trolling is a art,
  33. 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...
  34. Re:welcome to 1985! by JoeMerchant · · Score: 2, Interesting

    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.

  35. Re:C++? by siride · · Score: 2, Informative

    There is no such thing as actual pass-by-reference. Sure, a language might have fancy syntax for it, but it gets boiled down to pointer-to-a-value-which-is-itself-a-value. C just skips the sugar.

  36. Re:What... by MikeBabcock · · Score: 4, Informative

    Or even from the GCC build instructions:

    For a native build, the default configuration is to perform a 3-stage bootstrap of the compiler when `make' is invoked. This will build the entire GCC system and ensure that it compiles itself correctly. It can be disabled with the --disable-bootstrap parameter to `configure', but bootstrapping is suggested because the compiler will be tested more completely and could also have better performance.

    The bootstrapping process will complete the following steps:

         

    • Build tools necessary to build the compiler.
           
    • Perform a 3-stage bootstrap of the compiler. This includes building three times the target tools for use by the compiler such as binutils (bfd, binutils, gas, gprof, ld, and opcodes) if they have been individually linked or moved into the top level GCC source tree before configuring.
           
    • Perform a comparison test of the stage2 and stage3 compilers.
           
    • Build runtime libraries using the stage3 compiler from the previous step.
           
    --
    - Michael T. Babcock (Yes, I blog)
  37. Re:Crap by n+dot+l · · Score: 2

    Well, it depends on your compiler options and what subset of C++ you're talking about. Enable exceptions and you automatically get a slowdown in any function that declares a class with non-trivial destructor on the stack and does anything that can't absolutely be proven to never throw (such as an indirect function call, virtual call, or even [on certain platforms where hardware exceptions are magically turned into C++ exceptions] execute a single instruction). Yes, I know there are platforms with "zero-cost" exception handling, the problem is there are many many others without it.

    Then there's the debate about how best to expose (better yet: prevent) sloppy coding. Yes, in the hands of an expert, C++ offers no disadvantage, but it's often very difficult to find fifty experts (all without excessive egos) to work together on a project. And when you're on a platform where cache misses are *horribly expensive*, making a loop slow is as simple as typing "virtual" somewhere in a base class of some type who's methods you're calling (this besides bugging out the method that was meant to hide the inherited definition). That sort of shit can take *ages* to track down because it's utterly nonobvious when you open up the loop that's being slow. Overloaded operators and, to an extent, function overloading are also commonly culprits in this sort of situation - though I'd say the benefits pay for the cost in these cases.

    "Correct" C++, especially template code, besides taking ages to compile, also tends to run like shit in debug mode. Have you taken a look at the implementations of various std::algorithm methods? Layer after layer of overload selecting based on type traits. Do that in a loop and your debug build ends up orders of magnitude slower than a release because inlining is disabled. If your program's definition of correctness includes run time and you heavily use Boost or the STL, you can kiss your debug build goodbye and jump straight to printf debugging, because whereas you might have a 10% faster machine to counter the 10% cost of a debug build, chances are you're not going to have one 1000% faster just lying around somewhere.

    And then you have scenarios where OO in general can encourage bad habits, so a language like C where it's possible but ugly helps keep people on the straight-and-narrow. In my experience, there's a lot of merit to that way of thinking, but a lot of the specific cases where it comes up are subtle I really don't have the time to convincingly back up the general rule with a thousand little seemingly unconnected examples.

    Of course, I do use C++ a fair amount, limiting myself to whatever subset seems right for the job. It's entirely possible to do anything at all in C++, but that knowhow is resource that's rarer than you might expect and almost impossible to detect in an interview. If I had a project where I needed to hire a dozen other coders I would very strongly consider avoiding C (or, if I expect to have the time, be an utter Nazi about which subset of C++ I'm going to permit into the codebase).