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

546 comments

  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?

    1. Re:I think it's a sign of impending apocalypse by Anonymous Coward · · Score: 0

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

      I C what you did there.

    2. Re:I think it's a sign of impending apocalypse by PeterHammer · · Score: 1

      ++ mod for originality

  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 man_of_mr_e · · Score: 1

      After a few moments of thought, the answer seems obvious, so i'm ansing my own question. They will likely have a bootstrap C++ compiler written in C that is capable of compiling the full C++ compiler.

    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:Seems odd... by Joce640k · · Score: 1

      ie. They could use any of the current compilers for the 'bootstrap'...

      --
      No sig today...
    4. Re:Seems odd... by Anonymous Coward · · Score: 0

      GCC has always claimed that they are going the "we can bootstrap ourselves" way.

    5. Re:Seems odd... by Sigurd_Fafnersbane · · Score: 1

      Since there are platforms for which C++ compilers exist you can compile the compiler on one of these and then cross-compile for the target platform.

      This is also how you boot-strap a C-compiler on a platform it is not implemented for initially.

    6. Re:Seems odd... by man_of_mr_e · · Score: 1

      That would be wasteful, they could however strip down one of the current compilers and make it a "bare minimum" of features necessary to support the compiler.

    7. Re:Seems odd... by man_of_mr_e · · Score: 1

      Yes, that is one way to do it, but my point was that gcc has always prided itself on being able to bootstrap itself with minimal work, and without cross compilation. Cross compilation was sort of considered to be "cheating"

    8. 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...
    9. Re:Seems odd... by Sigurd_Fafnersbane · · Score: 1

      I get your point.

      It might be possible to maintain a "gcc-light" compiler written fully in C and then have the gcc build scripts completing this boot-strap compiler first. The gcc-light do not need to be fast or effective since it will only be used for boot-strapping. It might even be possible to make it as a pre-processor converting c++ into C.

    10. Re:Seems odd... by Yvanhoe · · Score: 0, Redundant

      The solution is called cross-compilation.
      You generate a binary for system Y on system X thanks to a compiler compiled in system X binary format.

      --
      The Wise adapts himself to the world. The Fool adapts the world to himself. Therefore, all progress depends on the Fool.
    11. 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

    12. Re:Seems odd... by Cyberax · · Score: 0, Redundant

      Cross-compilation from a working platform.

      It's not like many people don't have access to a platform powerful enough now. The need to bootstrap GCC from any platform only with K&R C has evaporated long ago.

    13. Re:Seems odd... by cyberthanasis12 · · Score: 1

      The real question is how do you compile the OS on the platform.

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

    15. Re:Seems odd... by Anonymous Coward · · Score: 0

      To be fair, it is right that the only real compiler (ie not a toy like Microsoft's) is built using a real language (ie not a toy like Microsoft's C#, or, heaven forbid, VB lol). C++ programmers are the best, most experience programmers around, and getting them on board the GCC project is undoubtedly a good idea.

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

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

    17. Re:Seems odd... by Jaydee23 · · Score: 0

      If I remember correctly, things may have changed, C++ is supposed to be implemented as a precompiler for C. Which means that for a new system you need only need to transfer the precompiled output (C) and then put it through a bootstrap C compiler on the new system. As I say things may have changed.

    18. Re:Seems odd... by Malc · · Score: 1

      Using C++ doesn't mean using all of the features of C++. It can be used as a better C, e.g. through the use of const. Maybe C supports const now, it's been a long time for since I wrote any.

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

    20. Re:Seems odd... by mog007 · · Score: 1

      While I don't know what the official C99 standard says, I know that GCC enforces const if your C program has it.

    21. 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.
    22. Re:Seems odd... by Anonymous Coward · · Score: 0

      Whoosh ;-)

    23. Re:Seems odd... by theshowmecanuck · · Score: 0, Offtopic

      Improper use of 'begs the question'. Begging the question is when you have already assumed an answer and are looking for the question for your assumed answer. It is not a question leading from the answer to another question. In that case it is better to use the phrase, 'it raises the question'. Take that grammar nazis!

      --
      -- I ignore anonymous replies to my comments and postings.
    24. 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.

    25. Re:Seems odd... by Anonymous Coward · · Score: 0

      Umm. No. The language used to write the compiler is not relevant to the input code of the compiler or the output program of the compiler. You can write a C compiler in Haskell if you wanted to. Bootstrapping isn't relevant either.

    26. Re:Seems odd... by sznupi · · Score: 1

      At least when looking at that lineage? (isn't "implemented" better than "invented"?)
      For example there was also Plankalkül (not the only one, I'm sure); with reality around it not helping any implementation efforts, which came only few decades later.

      --
      One that hath name thou can not otter
    27. 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.
    28. Re:Seems odd... by Anonymous Coward · · Score: 0

      that would be even _more_ interesting, plotting which compiler was used to compiler the next in line, so the tree backtracks to multiple roots and we can see how the evolution of compilers worked

    29. Re:Seems odd... by ixache · · Score: 1

      And the graph would be many-rooted, since up until at least the 80's, compilers were often implemented from scratch in assembler, just as it happened for e.g. C.

      And then it becomes much more hairy: it's been a good long time since the habit was taken to separate compilers into a front end (lexing, parsing) and a back end (optimization, code generation) with an intermediate representation; and then there are virtual machines and translators. Imagine all the possibilities! The graph would larger than Wikipedia itself!

      --
      Do I make sense? Please report if not.
    30. Re:Seems odd... by kiddygrinder · · Score: 0

      I'm sorry but you're wrong, the phrase "Begs the question" has been used widely over time with different correct and incorrect intents. 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. In this case it seems used correctly as the new generally accepted meaning of the phrase "begs the question" is "I'm putting this here to annoy Grammar Nazis".

      --
      This is a joke. I am joking. Joke joke joke.
    31. 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

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

    33. Re:Seems odd... by g4b · · Score: 1

      In the electronic age we started from scratch with a magnetic needle on the hard disk.
      But I started a next generation rewrite by killing some moths just yesterday.
      Yes. Moths. Because my alignment is chaotic evil.

    34. Re:Seems odd... by Anonymous Coward · · Score: 0

      Grace Hopper can be rearranged to spell "HAG CROP PEER". I think that says it all.

      feldicus

    35. Re:Seems odd... by theshowmecanuck · · Score: 1

      The problem with this phrase is that there are really no others to communicate that what someone is doing is forming some hypothesis and then framing a question to prove it... which is a kind of fallacy. It is not circular reasoning, which is using a proof for an issue to prove another issue is true, but which itself relies on the first problem to be its proof.. So by usurping its use for 'raises the question' it removes a clear avenue for it original purpose. 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. ;)

      --
      -- I ignore anonymous replies to my comments and postings.
    36. Re:Seems odd... by tomhuxley · · Score: 1

      But it does make it so.

      See what you think is a Van Dyke isn't one, if you want to be technical.

      The Van Dyke was a goatee plus a waxed, curled moustache. Along the way, the popularity of curled moustaches declined and the term Van Dyke came to mean any goatee with almost any kind of moustache (but no sideburns or other cheek hair). Now, the term for the mock "Van Dyke" (that you favour) has begun to collapse into the generic term goatee, which may or may include a moustache.

      And language moves ever forward ... or backwards ... or sideways.

    37. Re:Seems odd... by Tanktalus · · Score: 1

      Same answer everyone is giving for the compiler: cross-compilation. I regularly use my Linux/AMD64 box to compile the OS for my x86 32-bit boxes, including kernels, because using distcc just makes it faster. Now, I don't actually do the linking on AMD64 due to the way that distcc works, but I'm pretty sure it works the same way, too.

      I'm sure other platforms are about the same.

    38. Re:Seems odd... by Anonymous Coward · · Score: 0, Funny

      If your backdoor is red after insertion, you should have used a better lubricant.

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

    40. Re:Seems odd... by theshowmecanuck · · Score: 1

      So what happens when popular usage removes the ability to communicate important concepts like 'begging the question' since people cannot be bothered to understand the original meaning, as in Aristotle's usage? Do we have to start speaking Latin? For example, it is still important to be able to identify a logical fallacy and why it is so without having to resort to long explanations or speaking a dead language. However if people only understand the popular usage, popular because of ignorance to its real meaning (ignorance meaning just not knowing... not people being unintelligent), then we are left with the long explanations and dead language.

      --
      -- I ignore anonymous replies to my comments and postings.
    41. Re:Seems odd... by Anonymous Coward · · Score: 0

      Grace Hopper can be rearranged to spell "HAG CROP PEER". I think that says it all.

      Or "grope a perch".

      feldicus

      Thanks for your input, "fuc slide".

    42. Re:Seems odd... by tandr · · Score: 1

      ... assuming that you have compiled/assembled some equivalent of cp on the target platform already ...

    43. 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.
    44. Re:Seems odd... by Homburg · · Score: 1

      That's not entirely true - one of the most well-respected C++ compilers, Comeau compiles to C.

    45. Re:Seems odd... by Anonymous Coward · · Score: 1, Interesting

      I used to share this sentiment. And then I met their majority C equivalent, the same people who only know C but cannot program in C either.

      So I think what you meant to say is, C++ programmers who don't know resulting assembly generation for a particular compiler. Most C++ programmers working in performance critical areas can give you a good approximation of any particular segment of code. C programmers are no more optimization experts than their C++ counterparts, just on average due to C's much lower learning curve.

    46. Re:Seems odd... by Darinbob · · Score: 1

      Creating a cross compiler is a lot more difficult for one.

      However I think the biggest reason is that very often people want to use this compiler without having easy access to other systems. This is historical too. Ie, let's say you're running a Sparc shop, and have been using the official Sun compilers, but want to use GCC. Rather than require you to get access to VAX or other machine type to create the cross compiler, you can just use the built in existing Sun compilers on the Sparc to create your new GCC compiler.

      Remember, these compilers are very often compiled and built by the people using them. Historically the most common way of getting GCC was to build it yourself, not to find and download prebuilt binaries. So the goal of being able to build GCC from whatever existing and ancient C compiler you happen to have was very useful.

      Now days though, networking is much more pervasive, it's far easier to get prebuilt binaries, the cross-compile methods run a lot more smoothly, and so forth. So the reliance on an existing C compiler is much less.

      C++ if used right would be good for GCC. Trim down quite a lot though, to avoid bloating up; ie, don't use exceptions, STL, RTTI, etc. But use the Smarter-C-than-C stuff, like improved type safety, name spaces, basic class support, etc.

    47. Re:Seems odd... by ultranova · · Score: 1

      So what happens when popular usage removes the ability to communicate important concepts like 'begging the question' since people cannot be bothered to understand the original meaning, as in Aristotle's usage?

      It doesn't. You can simply say: "You are assuming the very thing you are trying to prove as a premise of the proof!" or "Your proof of X is only valid if X is assumed to be true". Or, in short, just say: "That's circular reasoning".

      Of course, you could also point out that you are using the phrase as an awkward English translation of something Aristotle said. The meaning of communication depends on the context, after all, so establish it first if you wish accuracy.

      Do we have to start speaking Latin? For example, it is still important to be able to identify a logical fallacy and why it is so without having to resort to long explanations or speaking a dead language.

      English is not primarily used for formal logic, so it should come as no surprise that it is not optimazed for such usage. And exact explanations are usually also long since they require framing the question as exactly as possible first.

      And no, you don't have to start speaking Latin. We have perfectly good domain-specific languages for doing formal logic nowadays; specifically, "begging the question" (as Aristotle used it) means that whatever was just said reduces to "x implies x", which is a tautology and thus true whether x is true or not.

      However if people only understand the popular usage, popular because of ignorance to its real meaning (ignorance meaning just not knowing... not people being unintelligent), then we are left with the long explanations and dead language.

      The popular meaning of any phrase of natural language is its real meaning. I'm sorry if you have trouble comprehending this concept, but it really is the key to understanding what a natural language is, how human minds work, and also very likely how to build strong AI. There was a concept, possibly invented by Aristotle, which was described in (bad) English as "begging the question"; for whatever reason, some people became enamored with this exact concept and this exact string of symbols to stand for it, to the point of claiming that anyone who uses them to any purpose is "wrong". Unfortunately for them, all these words are symbols by themselves, and put together, mean a pretty common thing - that someone said something that almost begs a follow-up question to be asked.

      Besides, why not use dead language? That way, when you say "petitio principii", people still don't gain magical knowledge of what you mean, but at least they aren't confused by the popular meaning; besides, that "begging the question" means a form of circular logic is far from obvious unless you already know it, so it's a pretty horrible translation to begin with.

      Finally... This is not going to change. "Begging the question" in the popular sense is a far more common occurence than "begging the question" in Aristotelean sense. Nothing you can say or do will change that, nor should it: after all, why should English-speakers in general give up an expression just to accomodate the inordinate fondness a small subset of them has for a particular meaning of it? Adopt another symbol for your use, or establish the context to establish the meaning, but either way stop whining that people don't care about what you think is "correct" usage of an expression.

      --

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

    48. Re:Seems odd... by mattack2 · · Score: 1

      No, her name was simply prescient about the physical bug that she supposedly found(*) in the computer.

      (*) OK, she didn't really find it. Most people wrongly believe that she did though. http://en.wikipedia.org/wiki/Software_bug#Etymology

    49. Re:Seems odd... by tater86 · · Score: 1

      Ignorance is what happens. The concept will be lost over time. Eventually someone will rediscover it, create a new name for it, and be a hero to pedants around the world.

    50. Re:Seems odd... by tomhudson · · Score: 1

      I used to share this sentiment. And then I met their majority C equivalent, the same people who only know C but cannot program in C either.

      I certainly won't disagree with you there ... the only thing that helps is curiosity. Curious people, with any language, will take the time to see what works, to test it themselves, to break things and find out why it broke, and to challenge presumptions.

      Give two people a compiler and 10 years - the curious person will be the one you want if you need any sort of optimization, because they'll know not only what works but why - and also be ready to try something different because times change since they last hit the text books.

    51. Re:Seems odd... by ChrisMP1 · · Score: 0, Redundant

      My kingdom for a mod point...

      --
      <sig>&nbsp;</sig>
    52. Re:Seems odd... by Tubal-Cain · · Score: 1

      You could stick the hard drive you intend to use on the new architecture in the compiling computer and copy the binary from there.

    53. Re:Seems odd... by Frnknstn · · Score: 1

      Well, that's a little misleading.

      Comeau does compile C++ to C, but not internally. It uses its own internal representations, but can output C code instead of a machine code. It's not strictly correct to call it a 'preprocessor'.

      It's also a little misleading to say 'Comeau, the well-respected C++ compiler, compiles to C'. Comeau claim to fame, and thus the source of the respect, is mostly because it can output C code, and because of great cross-platform support. The actual performance of the compiler itself is not the cause for the respect.

      --
      If it's in you sig, it's in your post.
    54. Re:Seems odd... by theshowmecanuck · · Score: 1

      So you think it is pedantic if someone desires the correct use of a word? Do you walk around and call black things white, and then look smug when people don't know what you're talking about? I'm not sure I understand people like you.

      --
      -- I ignore anonymous replies to my comments and postings.
    55. Re:Seems odd... by Anonymous Coward · · Score: 0

      He meant For all intents and purposes, I couldn't care less. Why the hell am i explaining this joke?

    56. Re:Seems odd... by Pseudonym · · Score: 1

      If they want some of teh nicer-sounding features of C++0a, things might start getting very horrible quite quickly.

      Not really. There is nothing in the back end of a retargetable C++ compiler which needs rewriting for C++0x.

      Indeed, there are very few bits of C++ which require back end code that's different from that which is required for a C compiler, assuming that the back end is bug-free. If you compile vtables and run-time type information down to C data structures and do name mangling in the front end (all trivial), then probably the only thing that makes a C++ compiler back end different from a C compiler back end is exception handling. This is precisely one of the features of C++ that I, were I a GCC developer, wouldn't want to do without.

      For completeness, I should point out that there is one complication: Different C++ front ends may produce new or sufficiently different code sequences such that existing back ends may not optimise them as well as they should. So while a change of C++ front end may not require changes to the back end for correctness, it may require them for performance.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    57. Re:Seems odd... by ultranova · · Score: 1

      So you think it is pedantic if someone desires the correct use of a word?

      Words and phrases can and do have multiple meanings. It is pedantic - and, in fact, incorrect, since it directly contradicts reality - to insist that one of these is "correct" and the rest "incorrect".

      Do you walk around and call black things white, and then look smug when people don't know what you're talking about?

      It is you who wants to co-opt an expression in common usage to mean something else instead.

      I'm not sure I understand people like you.

      Yes, it must be difficult to understand people if you can't deal with ambiguity.

      --

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

    58. Re:Seems odd... by Philip_the_physicist · · Score: 1

      I think we might be talking at cross purposes here: AIUI, GGP suggested that a C++ to C translator could be written in a macro language, which would require a front-end (C++ -> C -> internal tree -> asm -> binary). For basic C++ this would be fairly straightforward, but doing things like template expansion robustly would be slightly tricky at best (although C++'s rules about space around the angle brackets would make this far easier to do than with, say, java's rules).

      If I were trying to translate a C++ program to C, I would use one void* per thread (for the object being thrown) and then setjump at the start of the try block, and if it is the first execution, enter the try block. When an exception is thrown, we can assign the thrown object to the pointer, and longjump. The second time we arrive at the start of our try block, we are sent to the catch block.

    59. Re:Seems odd... by man_of_mr_e · · Score: 1

      Also, Comeau C++ was one of the first compilers to fully implement the full C++ language back in the day..

    60. Re:Seems odd... by man_of_mr_e · · Score: 1

      When I wrote that, I suspected someone might go all etymological on my ass. However, I am not a language purist. And while I understand that the "pure" meaning of "begging" in the phrase is not "to ask", the fact is that that it now means something else than what it did in Latin.

      "begging the question", based entirely upon english language meaning is correct for this term, even if not historically accurate.

      "raises the question" is linguistically meaningless.. how can you "raise" a question? It's another turn of phrase, but linguistically speaking is less accurate than "begs the question".

      So I choose to use the common terminology because it makes more sense to more people. I couldn't care less about your historical accuracy.

    61. Re:Seems odd... by OptimusPaul · · Score: 1

      This is very informative, I am going to grow out my goatee into a Van Dyke. Does anybody know where I can get mustache wax?

    62. Re:Seems odd... by Pseudonym · · Score: 1

      The difficult bit about C++ EH isn't altering the program counter and stack pointer, it's calling the destructors on all of the stack-allocated objects. It can be done, but it's hard to do it in a way that doesn't hurt the performance of code that never calls an exception.

      Oh, and you also need a smarter linker than you do for C because of template instantiation and the one definition rule, but GCC already has that.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  3. Great by jimmydevice · · Score: 2, Funny

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

    1. Re:Great by Anonymous Coward · · Score: 0

      I don't get the joke. What preprocessor output? Are you talk about CFront (the c->c++ preprocessor). That is no longer the case. C++ isn't preprocessed into C.

    2. Re:Great by JamesP · · Score: 1

      Warning! 'static const AType' invalid lside value 'static const AType'

      --
      how long until /. fixes commenting on Chrome?
  4. C++? by Anonymous Coward · · Score: 0, Flamebait

    C++ is the most horrible language I've ever had to write code in. I think they should have sticked to pure C.

    1. Re:C++? by Anonymous Coward · · Score: 1, Interesting

      AC you got that right! C++ is macro for programmers that don't grok struct and pass by ref

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

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

    4. Re:C++? by Homburg · · Score: 1

      C++ is also required to be more-or-less compatible with C, and with various different pre-standard dialects of C++, which both prevents removing some of unpleasant parts, and means that new features have often had to be added in fairly baroque forms.

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

      I would call the "high level" part a goodness. It's overly complex, making it too complex to understand, and hard to read and write code. C is already hard, but this is because of the low level part which you can't go without, and C++ just makes it insane.

      And some language decisions are troubling. Abusing left and write shift with streams? I nearly puke when I see code like that. Couldn't they just have a 'write' and 'read' methods? It's confusing as to whether the code is doing shifts, or writes, or what, making it hard to read.
      Template metaprogramming? Macros were already a way to make everything horrible, now there are even more things that allow you to do this. While it is a useful feature, any template code is nearly incomprehensible.
      References for me are just more complicated pointers that only make code even harder to understand. And if you're doing high-level OO programming you should be avoiding using such constructs, just pass or return an object that carries the required information. Returning values through arguments like that is a bad idea, like all the things that references allow you to do. f(x) changing the value of x is a completely unexpected and surprising result for me. In C at least it had to be f(&x). Not to mention the use of & for references confuses the hell out of me.

      Everything new, including the good things, like == overloading, and the way they are implementing, contributes to the extreme complication and insanity of C++.

      C++ is the most horrible Object Oriented system you could add on top of C. Even Objective-C is better.

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

    7. Re:C++? by mike260 · · Score: 1

      So pick a subset you're happy with and stick to it. If that subset is basically pure C then so be it. But why whinge?

    8. Re:C++? by Anonymous Coward · · Score: 1, Informative

      Even Objective-C is better.

      What do you mean "even"? I consider Obj-C to be a pretty great language.

    9. Re:C++? by Coppit · · Score: 1

      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.

      Why is it that this reply is insightful for C++ but would be funny for Perl?

    10. Re:C++? by u17 · · Score: 1

      I agree that iostreams are ugly, but they are not strictly part of the language and you don't have to use them if you know any better.

      Templates are actually quite useful for performance, when you want parameters incorporated into the code at compile time, instead of evaluated by the cpu at run time. I acknowlege that this can be taken to the extreme: I know of one guy implemented a C++ template raytracer, where the image is produced entirely by the compiler at compile time instead of by the program. But if you care about performance, templates let you get away with less code than C, and no loss of performance at all.

      Operator overloading is crucial for when you implement algebraic data types. Have you seen the Vector3d class in Java3D? If you ask me to choose between the potential for abuse and overly-verbose hard-to-read code, I'll take abuse without hesitation.

      I'll give you the one about passing by reference. In my book non-const references should basically only be used in operator functions, but it seems a significant number of C++ programmers thinks differently. Still, again the fault is not with the language but with programmers.

      I guess you could sum all of this up this way: C++ is a great language, and you can write much better code in C++ than in many, maybe even most, other similar languages, but it is also much easier to abuse by bad programmers. If you have a good team that you can trust, then go for it!

    11. Re:C++? by Two9A · · Score: 1

      Let's ignore that C doesn't even have "pass by reference"; there's either pass by value or pass by pointer-to-a-value, which is itself a value.

      I never understood the animosity against C++. Sure, it's a larger language (you just need to look at the difference in sizes between K&R and Stroustrup to see that); and sure, g++ spits out utterly incomprehensible errors when you work with the Template Black Magic; but on the whole, I find it makes for a more structured program than the equivalent C.

      Of course, the only way to fly is Brainfuck; don't let anyone tell you otherwise.

      --
      xkcdsw: the unofficial archive of Making xkcd Slightly Worse
    12. Re:C++? by Anonymous Coward · · Score: 0

      You don't know the difference between "its" and "it's", so you're probably wrong.

    13. Re:C++? by coryking · · Score: 1

      This is the part where I point out that c# can act as a low-levelish language. You can do pointer arithmatic and shoot yourself in the foot with buffer overruns just fine writing unsafe code.

      Of course writing such low-level code in C usually looks more elegant than doing it in C#.

    14. Re:C++? by Anonymous Coward · · Score: 0

      I wholly agree. For some reason newbies love operator overloading, which is the most damning if planned improperly.

    15. Re:C++? by Hurricane78 · · Score: 1

      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.

      Uuum, I have done systems programming in Pascal (starting at TurboPascal 3.0), and you can do everything perfectly well in it. If you can do it in C, you can do it in Pascal. The effort is about the same. No need for additional low-level stuff. Interrupts, ports, registers, pointers, etc... Everything there.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    16. Re:C++? by daniel_newby · · Score: 1

      I never understood the animosity against C++.

      Many of us were around for the long trial by fire that was needed to figure out which features of C++ to use and which to avoid. "Modern C++" gets good results from a careful set of language features and libraries, but many folks still get flashbacks from the language itself.

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

    18. Re:C++? by tomhudson · · Score: 1

      We may have gained a lot in the last couple of decades, but those early Borland compilers (Turbo C, Turbo Pascal, Turbo Asm, Borland C++) were just so righteous!

    19. Re:C++? by HiThere · · Score: 1

      That may be, but references are much nicer to work with than pointers. The only problem is you can't delete them, you've got to wait for them to go out of scope. This makes using them with the heap problematic.

      I purely despise the syntax that C came up with for using values pointed to by pointers. And pointer/integer conversions, etc. should never have been allowed. It makes garbage collection a guessing game. Garbage collection *should* be a part of any decent language. The only reason it isn't reasonable for C/C++ is the infernal mucking around with pointers/integers that it allows. Pointer arithmetic should be absolutely forbidden.

      That said, I'm not sure whether I prefer C over C++, if one restricts oneself to a decent subset of C++...but some of the libraries that I want to use are only C++ libraries...so that sort of forces the issue for me.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    20. Re:C++? by siride · · Score: 1

      I don't see how references are any better than pointers, really, except you aren't allowed to do certain things. Whoop-dee-doo. If you can trust those certain things, then just don't ever do them in your code. Boom, you have the safety of references without having to use references.

      I'm not sure what your problem is with the syntax for pointers in C. It makes pretty good sense. I guess the only annoying thing is that a star is used both to indicate type, and also as a dereferencing operator. I suppose they could have used, say, a ^ to indicate the type and a * for dereferencing. Either way, the two contexts are pretty clearly separated, so it doesn't seem to be a problem for me.

      Sure, GC would be nice, but consider the versatility of C's targets. C demands absolute control over what's going on. GC violates that as the GC is off on its own, outside of your direct control as programmer. It may also be unnecessary. Many interesting programs can be written in C with manual memory management and very little risk for leaks. It's only the large programs that would benefit from GC. And even then, having a sane model of object lifetime would be the better choice. Honestly, to me, GC is a cop-out. You are saying "I'm too lazy to make sure I know what is needed when, so I'm gonna let the run-time heuristically determine it for me and hope I don't run out of memory before it can do its job!" But I guess since developer time is more expensive than computer time, GC is the way we are going to go.

    21. Re:C++? by VisceralLogic · · Score: 1

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

      Why would you do this? AppleScript is a scripting language, primarily for application automation (which, incidentally, you'd probably have trouble doing in pure C++), not for writing multi-threaded CFD codes.

      --
      Stop! Dremel time!
    22. Re:C++? by shutdown+-p+now · · Score: 1

      References for me are just more complicated pointers that only make code even harder to understand. Returning values through arguments like that is a bad idea, like all the things that references allow you to do. ... f(x) changing the value of x is a completely unexpected and surprising result for me. In C at least it had to be f(&x). Not to mention the use of & for references confuses the hell out of me.

      References were originally added to C++ to provide for an efficient argument passing mechanism for large-sized values which would not require an explicit address-of. The main reason why you need it is for operator overloading - then you have e.g. a matrix class, you'd want to overload operator + for values of that class, not for pointers to then. I.e. you want to be able to write:

      matrix m1, m2;
      ...
      m1 += m2;

      rather than, say:

      matrix m1, m2;
      ...
      &m1 += &m2;

      Pretty much everywhere I've worked, C++ coding style explicitly prohibits using parameters of non-const reference types in all cases. After all, pointers are still there, so you absolutely can still declare a parameter as int* p, and pass a value as &x. This is done precisely for the reasons you give - so that it is clear what is mutated on exit from the function.

      And if you're doing high-level OO programming you should be avoiding using such constructs, just pass or return an object that carries the required information.

      Not all things are value-copyable. Sometimes you really want to create an object, and pass a reference to it around - for example, when ownership changes. Of course, you'd use std::auto_ptr or std::unique_ptr for that, not a C++ reference.

    23. Re:C++? by Jamu · · Score: 1

      A reference always "points" to a variable. This is useful because you don't need to account for null pointers when they aren't required, and function parameters are more exact.

      --
      Who ordered that?
    24. Re:C++? by Jamu · · Score: 1

      Garbage collection *should* be a part of any decent language.

      I don't understand your reasoning for this. Why force garbage collection on a program that doesn't need it?

      --
      Who ordered that?
    25. Re:C++? by hazah · · Score: 1

      Pointers, and by extension pointer arithmetic operations in C (and C++) are 1 to 1 mappings to some very common assembly instructions. That is, it's merely a way to use expressions for the type of code that deals with addressing raw memory. If you've found that you're using a lot of code that does pointer arithmetic but can't figure out why, well then you're doing it wrong (tm). This type of code belongs safely tucked away in a well tested library routine. However, to suggest that you should never ever be able to write code that performs these operations literally means you will sell yourself short in the long run when you come across a problem that *requires* that type of bit fiddling. It doesn't happen often, but it does happen.

    26. Re:C++? by HiThere · · Score: 1

      It doesn't need to be always enabled. A compiler switch to enable it is quite reasonable. But it needs to be always available. (And saying that garbage collectors, like Bohm[sp?], are available doesn't satisfy the requirement. But a good, fast, garbage collector for C/C++ is basically impossible, because you never know which integer is going to be converted into a pointer. Or added to a pointer to yield another pointer.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    27. Re:C++? by HiThere · · Score: 1

      When I've needed to do this kind of thing, and I have, just not on an 8086 descendant platform, I wrote a separate function in assembler. Enabling this doesn't justify allowing the compiler language to permit this foolishness. (Well, not necessarily foolishness. That was the only way I could do a random access read from the disk..library problems. Still, not an argument for allowing this to be done from within the language.)

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    28. Re:C++? by Jamu · · Score: 1

      Why not simply overload the new operator to handle garbage collection (keeping it's normal use intact)?

      --
      Who ordered that?
    29. Re:C++? by HiThere · · Score: 1

      That doesn't tell you whether there are references that aren't generated through the new system. (E.g., an array on the heap that has a user generated pointer to an array element.)

      So you can end up with stray pointers to memory that's already been released...and possibly reused.

      --

      I think we've pushed this "anyone can grow up to be president" thing too far.
    30. Re:C++? by man_of_mr_e · · Score: 1

      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.

      Don't get me wrong. I like C++, and I also respect it. But I respect it in that "handling nitroglycerine" sort of way rather than in that "treat it like a samsonite bag" kind of way that you can with C# or Java.

      Just because you CAN write entirely high level code in C++ doesn't change the fact that it's a mine field filled with explosives waiting to go off at the first misstep.

      Yes, you pay for that ruggedness in more modern languages in terms of run-time performance and other factors, but that's what makes C++ so odd... it's that mix of both, that makes it neither.

    31. Re:C++? by man_of_mr_e · · Score: 1

      True that you can do it, but it's not the default mode. You can take off the safeguards, and run without shielding, but watch out for the radiation.

    32. Re:C++? by man_of_mr_e · · Score: 1

      TurboPascal is not Pascal. It's TurboPascal. It's a "Pascal-like" language.

    33. Re:C++? by hazah · · Score: 1

      But this is a system's language which is meant for precisely allowing this type of programming from within the language (and avoiding platform specific assembler code while performing the operations themselves using slightly higher level expressions). I'm not sure if the benefits of what you say outweigh the downsides considering their original intended purpose.

  5. Transitioning from C to C++ by Decollete · · Score: 1

    Although I am not a contributor (for now at least, maybe), I want to follow how the developers will transition from C to C++. I mostly use C at work but I want to learn C++ as well. However, most of the time, I'd rather code in C than in C++ because I am that uncomfortable with it. Maybe the last time I used it is back in college, and that translates to not knowing much of it at all.

  6. Linus will raise! by Anonymous Coward · · Score: 1, Interesting

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

  7. What... by f3rret · · Score: 1

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

    --
    Admit nothing. Deny Everything. Make Counter-accusations.
    1. Re:What... by Ckwop · · Score: 3, Informative

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

      Enjoy

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

    3. Re:What... by BetterThanCaesar · · Score: 1

      First you compile it with another compiler. Then you have a binary with which you can compile the compiler.

      --
      "Stop failing the Turing test!" -- Dilbert
    4. Re:What... by BetterThanCaesar · · Score: 1

      Quis compilat ipsos compilatores?

      --
      "Stop failing the Turing test!" -- Dilbert
    5. 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.

    6. Re:What... by josgeluk · · Score: 5, Funny

      Quis compilabit ipsos compilatores?

      ecco, tibi fixi .

    7. Re:What... by hey · · Score: 1

      The other compiler can be a previous version of the same compiler.

    8. Re:What... by sznupi · · Score: 1

      %chosendeity gave us the first one.

      BTW, now is the time you should really start to wonder what builds those very high cranes used to build skyscrapers ;p

      --
      One that hath name thou can not otter
    9. Re:What... by Anonymous Coward · · Score: 2, Funny

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

    10. Re:What... by Anonymous Coward · · Score: 0

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

      Interesting question, indeed. Ask FreePascal's guys, http://www.freepascal.org .

    11. Re:What... by oldhack · · Score: 1

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

      Sup, DAWG! We heard... wait, who called me?

      --
      Fuck systemd. Fuck Redhat. Fuck Soylent, too. Wait, scratch the last one.
    12. Re:What... by ckaminski · · Score: 1

      Jack cranes build themselves, they're that cool. Like Chuck Norris.

    13. 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)
    14. Re:What... by Anonymous Coward · · Score: 1, Funny

      Yo dawg.... I heard you like to compile compliers, so I compiled a compiler with your compiler.

    15. Re:What... by zebslash · · Score: 1

      Well, that's true, but only in practice. But that would not answer the interrgogation of the original poster, which is the probblem of the egg and the chicken.

    16. Re:What... by nsaneinside · · Score: 1

      it's also in a dead language

      Minime, fatue! Lingua, donec sunt qui ea loquantur, est non mortua.

  8. 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 bonch · · Score: 0

      So sarcastic, it makes my teeth itch.

    2. Re:Out of the ashes and into C++ by Anonymous Coward · · Score: 0

      Great idea! This will surely help steal back users from LLVM/clang.

      Disregarding the sarcasm in the rest of the post, LLVM's compiler is currently implemented by replacing GCC's backend with LLVM. This means C++ code gets into the compiler and whilst GCC is "Mainline = C only" it is impossible to declare GCC+LLVM an officially supported combination.

      By most accounts I've read, LLVM generally produces superior code and is designed to function as a research and experimentation platform so it's an obvious choice to use that as the backend (perhaps keep the GCC specific one but de-emphasise it).

      On the other hand, it may not have much to do with LLVM at all and instead just be intended to allow use of classes and stronger type checking for better internal organisation.

    3. Re:Out of the ashes and into C++ by nitehorse · · Score: 1

      You jumped right on the LLVM part, but apparently don't know what clang is. You should read about clang. http://clang.llvm.org/

    4. Re:Out of the ashes and into C++ by serviscope_minor · · Score: 1

      Great idea!

      Indeed.

      This will surely help steal back users from LLVM/clang.

      I hope so.

      So, you don't think that writing in a higher level language will lead to better performance and features? Perhaps you should start campaining to have LLVM rewritten in assembly language (or the LLVM intermediate language).

      As for licenses, time will tell. Back in the Bad Old Days, every vendor and his dog had their own compiler. Because most vendors were not terribly good at writing compilers, writing portable code was really, really hard. Given how much more complex compilers have become, we really don't want to return to those days. GCC and the GPL have really helped in this regard.

      Being the only fully featured, open source C++ compiler meant that the choice was low cost, low effort and openness, versus very high cost, high effort and closedness, the vendors chose GCC. Having basically a common. good, standards compliant compiler has made my life so much easier.

      So yeah as someone who suffered for years under the heel of shoddy vendor compilers, I really hope that the compiler world does swing back to gcc. It'd be better for business all round.

      --
      SJW n. One who posts facts.
    5. Re:Out of the ashes and into C++ by ZorbaTHut · · Score: 1

      As opposed to the closed inaccessible LLVM/Clang combo?

      The GCC developers have shown their ability to compete with MSVC. For a while, they had the edge. They no longer do, and part of that, from what I know, is thanks to how grim and unmaintainable the GCC codebase is.

      Personally, I'm quite excited for something better, and I'm really excited for something better that can be embedded in other projects.

      --
      Breaking Into the Industry - A development log about starting a game studio.
    6. Re:Out of the ashes and into C++ by ixache · · Score: 1

      Watch out! They've let the tags loose again! Oh no!

      --
      Do I make sense? Please report if not.
    7. Re:Out of the ashes and into C++ by ixache · · Score: 1

      Joking aside, I can totally see where you're coming from.

      --
      Do I make sense? Please report if not.
    8. Re:Out of the ashes and into C++ by Anonymous Coward · · Score: 0

      you totally missed the sarcasm, man, and the point.

    9. Re:Out of the ashes and into C++ by JamesP · · Score: 1

      What, templates are very useful... if you want to kill yourself

      Also, levels and levels of inheritance

      --
      how long until /. fixes commenting on Chrome?
    10. 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.

    11. Re:Out of the ashes and into C++ by Anonymous Coward · · Score: 1, Insightful

      vendors chose gcc? lol. *BSD uses gcc but they're all drooling at clang and OpenBSD was putting time and effort into pcc. BeOS used gcc, but only for x86. If metrowerks hadn't dropped the ball, they would have stuck with them. Apple uses gcc but are investing a lot of time and money into clang. So what other vendors (not linux distros) chose gcc?

    12. Re:Out of the ashes and into C++ by trialcode · · Score: 1

      But C++ isn't a higher level language, they're not gaining anything but hidden complexity.
      The low level knowledge you have to possess to use the high level features correctly make them practically useless and you often end up spending more time coaxing the language to do the right thing than you would have spent writing the code yourself.

      I can assure you that whatever it is that's holding the project back it has absolutely nothing to do with a lack of language features.
      Everything that should be done in C++ can be done easier and simpler in C by reasonably competent programmers, the rest of C++ is pure madness and it will slowly seep into the project regardless of coding standards.

    13. Re:Out of the ashes and into C++ by Anonymous Coward · · Score: 0

      So I guess it's time you learn a little bit about software development and stop playing around with broken toys

    14. Re:Out of the ashes and into C++ by Spewns · · Score: 1

      But C++ isn't a higher level language, they're not gaining anything but hidden complexity. The low level knowledge you have to possess to use the high level features correctly make them practically useless and you often end up spending more time coaxing the language to do the right thing than you would have spent writing the code yourself. I can assure you that whatever it is that's holding the project back it has absolutely nothing to do with a lack of language features. Everything that should be done in C++ can be done easier and simpler in C by reasonably competent programmers, the rest of C++ is pure madness and it will slowly seep into the project regardless of coding standards.

      I wish I had mod points.

      From TFA:

      "Hey guys, we're going to use C++! Actually, we probably shouldn't use too much because people will either have a hard time understanding it or will often misuse it, because afterall, it's C++. And C++ is a gigantic language so let's bikeshed over what we should allow and shouldn't allow."

      You know you picked a crappy language for developing your project in when you're worried about people... you know... developing your project in the language.

    15. Re:Out of the ashes and into C++ by tomhudson · · Score: 1

      Geek insult - "go template yourself."

      By the time they finish compiling, they'll be dead.

      Templates look ugly for a reason. They are ugly.

      They're a shortcut. Funny thing is, the same people who go all gaga over them go "OMG the pre-processor is the devil!" for those of us who make extensive use of the pre-processor.

    16. Re:Out of the ashes and into C++ by Anonymous Coward · · Score: 0

      Namespaces are nice.

      And reusable generic data structures (lists, dictionaries and the like) in C are butt ugly macro hacks that are in no way prettier than their C++ template counter parts.

    17. Re:Out of the ashes and into C++ by trialcode · · Score: 1

      Everyone is already doing namespaces in C, nothing new here but syntactic sugar.

      I typically use three types of data structures in my C code, a vector type that stores pointers, a hash type that maps pointers to pointers (remember that a string is a simple pointer in C), and a set type that stores pointers. All this without any ugly macro hacks. Not as 'safe' as the generic variants but safe enough and a lot easier on the eyes.

      They're nice features, and two good examples of features that a lot of C-programmers wouldn't mind being added to the language. But they are not a good enough reason to choose C++ considering the complexity price.

  9. From the article it is obvious by FithisUX · · Score: 0

    that they are in need of ObjC without garbage collection. Why use C++ and artificially constrain its capabilities? There is also GnuStep project and ObjC has a clearer and simpler syntax than C++ with single object inheritance, and C99 extension (easy migration path). I cannot understand their reasoning for C++ if they are targeting a single subset and not the full standard. The only plus for C++ is the extensive use of IDEs. Otherwise it makes no sense.

    1. Re:From the article it is obvious by Rockoon · · Score: 1, Interesting

      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."
    2. Re:From the article it is obvious by Mad+Merlin · · Score: 0

      They're allowing the STL but not custom templates. The STL alone makes C++ worth using.

    3. Re:From the article it is obvious by Rockoon · · Score: 1, Troll

      So, a library? Really? Think about it.

      --
      "His name was James Damore."
    4. 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).

    5. Re:From the article it is obvious by Anonymous Coward · · Score: 1, Informative

      GCC already uses a garbage collector internally although it has to be triggered explicitly.

      The two main reasons for choosing a subset of C++98, instead of a different language, were mentioned on the mailing list. The most important reason is C++ will be the easiest to pick up by GCC hackers which are mostly accustomed to plain C.
      The second reason mentioned were specific features of C++ like simple templates (STL containers) and multiple inheritance. They're taking everything slowly and at the moment there's no consensus even about the use vtables and RTTI.

    6. Re:From the article it is obvious by Cyberax · · Score: 1

      I'm aware of garbage collector in GC. However, it's completely deterministic, and GCC people don't want to change it.

      I tried to do some GCC hacking 3 years ago before I gave up and used LLVM.

    7. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      Would have a point about the GC if gcc didn't already use it almost anywhere, because they couldn't find and fix all the memory leaks in their software.

    8. Re:From the article it is obvious by Anonymous Coward · · Score: 1, Informative

      If anyone is interested about the speed of various different dispatch mechanisms, I've done some profiling

    9. Re:From the article it is obvious by DrXym · · Score: 1
      that they are in need of ObjC without garbage collection. Why use C++ and artificially constrain its capabilities?

      C++ isn't a constraint. There are far more people capable of coding in C++ than in Objective C. And with Apple jumping ship for clang the implementation in gcc runs a serious risk of being deprecated or going bit rotten. Neither of which are justifications for using it internally.

    10. Re:From the article it is obvious by spedrosa · · Score: 1

      There is no such thing as a slow language.

      There are only slow implementations.

    11. Re:From the article it is obvious by Anonymous Coward · · Score: 1, Interesting

      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.

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

    13. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      Because ObjectiveC is a slow shit?

      [Citation needed]

      What are the different benchmarks you ran that showed that it was slow? Please post numbers, and code if possible. I wouldn't recommend Objective-C for compiler writing, either, but your complaints about speed are dubious.

      They're using C++ for syntactic sugar, but my guess is it's a slippery slope to Hell. How difficult would it be for them to pare down the C++ compiler to only support the syntactic sugar? Otherwise, I suspect the syntactic sugar line is going to lead to full C++ Hell pretty quickly. (As much as I wouldn't recommend Obj-C, I'd recommend full C++ even less.)

    14. Re:From the article it is obvious by Anonymous Coward · · Score: 1, Insightful

      Obj-C is why Apple is running circles around MS and Google. Whether you love em or hate em, Apple innovates highly polished products the fastest. MS: stuck with C++ no real innovation in a decade. Google: Love some of their stuff, but they haven't really standardized on one language. A lot of Google's stuff is 1/2 finished as a result.

      Dynamic typing is a very important enabler of tight code (closures for example). It also enables far beta meta programming like unit tests and build automation. Static typing is the problem, not the solution.

      Of course this stuff flies over the heads of most business deciders, and also programmers who enjoy disentangling spaghetti instead of writing unit tests because it gives them job security! More Parmesan with that?

    15. Re:From the article it is obvious by BitZtream · · Score: 1

      No, the ObjC compiler is ass, like GCC in general when it comes to producing fast code. Stop blaming the language for a problem that is clearly determined by the interpreter.

      --
      Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
    16. Re:From the article it is obvious by Tony · · Score: 1

      Nope, not a troll.

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

      This is also one of C++ weaknesses. Troubleshooting templates is a royal pain in the ass. I'd rather chase a pointer to hell and back than deal with another set of poorly-written templates. And templates are almost invariably poorly-written.

      They are damned useful when done right, though.

      Objective-C has only pointer containers which are untyped.

      True, that. Objective-C sacrificed compile-time type checking for flexibility. Well-written Objective-C code is almost beautiful (something that can't be said even for well-written C++ code), but you really need to be careful with your types.

      'Const' support? Nope.

      RAII and smart pointers? Nope.

      "Smart pointers" are really just a kludge to fix up a poor language design choice. RAII isn't all that vital in Objective-C, either.

      You are attempting to say Objective-C is deficient because it doesn't support the design patterns you use in your C++ code, when those design patterns are necessary because of the language itself.

      Memory management in Objective-C is quite convoluted, btw.

      You ain't kidding. It's getting easier with each iteration of the language, but the GC is kinda particular. Conscientious use of refs is a must.

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

      Riiiight.

      Again, I think you are judging Objective-C based on your C++ experience. Late binding, associated references, adding messages to existing classes at run-time, message forwarding, and so on are all excellent general-purpose programming idioms that aren't supported in C++. Couple that with introspection (which is supported in C++, to a degree), and you can write very powerful fully-OO programs.

      Objective-C isn't perfect. No language is. But it certainly isn't as anemic as you seem to think.

      --
      Microsoft is to software what Budweiser is to beer.
    17. Re:From the article it is obvious by geminidomino · · Score: 1

      Do you mean it's completely NON-deterministic? Because otherwise I'm a bit confused by the contradiction between this post and your original one.

    18. Re:From the article it is obvious by Cyberax · · Score: 1

      "This is also one of C++ weaknesses. Troubleshooting templates is a royal pain in the ass. I'd rather chase a pointer to hell and back than deal with another set of poorly-written templates. And templates are almost invariably poorly-written."

      I have debugged code which uses Boost MPL. It looks scary but once you understand how templates work it's not different from usual debugging. Apart from the fact that it's done at compile time instead of runtime.

      And plain simple template applications (containers, algorithms) are even easier.

      "True, that. Objective-C sacrificed compile-time type checking for flexibility. Well-written Objective-C code is almost beautiful (something that can't be said even for well-written C++ code), but you really need to be careful with your types."

      Untyped code is filed under 'ugly' in my book. I generally prefer maximum compile-time safety with as much typing as possible (my favorite language is Haskell :) ).

      ""Smart pointers" are really just a kludge to fix up a poor language design choice. RAII isn't all that vital in Objective-C, either.

      You are attempting to say Objective-C is deficient because it doesn't support the design patterns you use in your C++ code, when those design patterns are necessary because of the language itself."

      No. Pure C also suffers from this. Just look at all those 'goto cleanup' in the Linux kernel. Which is nothing more than a poor man's destructors.

      I won't argue about your other points, since they are subjective. Personally, I'd rather prefer good pattern matching to all the OO stuff.

    19. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      As someone experienced in both Objective-C and C++, I agree with you completely.

      Too many people try to use the features in Objective-C as a hammer to solve all problems, using NSArrays as tuples and NSDictionary's as key-value structures, instead of using C arrays or structs. C++ containers are much better, they generally optimize down to the same code as if you were to hand-code it in C. With Cocoa classes, you have a crap load of call overhead and dynamic typing going on. I've managed to turn applications written in Objective-C that ran at a snails pace into mind-blistering fast code, simply by sprinkling a little C or C++ love into the mix.

    20. Re:From the article it is obvious by Cyberax · · Score: 1

      No, the current GC in GCC is deterministic. I.e. if you run GCC with two identical inputs on two computers, GC will collect the same objects at the same time.

    21. Re:From the article it is obvious by Tony · · Score: 1

      Untyped code is filed under 'ugly' in my book. I generally prefer maximum compile-time safety with as much typing as possible (my favorite language is Haskell :) ).

      Haskell is beautiful. I wish I had more opportunity to use it, rather than just playing around with it. You have good taste.

      I won't argue about your other points, since they are subjective. Personally, I'd rather prefer good pattern matching to all the OO stuff.

      Not really subjective. You made the assertion there wasn't much there for general-purpose computing; I mentioned several features that are good for general-purpose computing. There's nothing subjective there, other than whether or not you like them.

      Obviously, many people have found them useful, from the original NeXTStep coders andLotus Improv creators to the modern OS X and GNUStep developers.

      In any case, while I prefer Objective-C over C++ (it just fits my style better), I can definitely understand the desire for stronger compile-time type enforcement. That alone is sufficient to warrant C++ over Objective-C, especially for a project that relies on input from many other people of varying skill levels.

      My inner language fanboi came out when you glossed over most of the unique features that make Objective-C a versatile language.

      Oh, one other complaint about it to add to your list: current implementations don't properly support private variables and messages.

      --
      Microsoft is to software what Budweiser is to beer.
    22. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      Memory management in Obj-C is not convoluted, you're just slow...

      If you alloc or retain an object then you need to release it...that's about it. Now there's also garbage collection for the kindergartners that can't follow the rules.

      Where's the depth to your argument? Why are each of those things important? Did you know that you can use C++ from Obj-C?..

      Objective-C is the shit. It's what Java should've been but they weren't smart enough to steal the whole API and tool chain...easier to recreate it, poorly. O

    23. Re:From the article it is obvious by PCM2 · · Score: 1

      MS: stuck with C++ no real innovation in a decade.

      Other than that whole C#/.Net Framework thing, you mean. But I guess we can ignore that.

      Google: Love some of their stuff, but they haven't really standardized on one language. A lot of Google's stuff is 1/2 finished as a result.

      Right, because Google projects get slowed down because developers keep switching programming languages midstream. Last I heard they were rewriting GMail in a combination of Oberon, Scala, and Z-80 assembly language.

      --
      Breakfast served all day!
    24. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      did mr. grumpy miss his coffee fix this morning?

    25. Re:From the article it is obvious by shutdown+-p+now · · Score: 1

      Of course there are such things as slow languages. If a language specification, for example, mandates arbitrary-precision arithmetic, then you can't get around having to implement it, and it will inevitably be slower than native CPU arithmetic operations.

      Sure, you can try to optimize it - e.g. use native, and only switch to your own custom bigint implementation on overflow. But you still have to do those overflow checks, and they aren't free.

      Similarly, if a language e.g. mandates matching strings for every member lookup, there's only so much you can do to optimize that. Cache lookup results, precompile "hot" branches, etc - however hard you try, you won't beat a direct function call.

    26. Re:From the article it is obvious by shutdown+-p+now · · Score: 1

      Obj-C is why Apple is running circles around MS and Google.

      Wait, wasn't it because Apple is a UI/UX genius making polished products that Just Work?

      MS: stuck with C++ no real innovation in a decade.

      Erm... ever heard of C#?

      Google: Love some of their stuff, but they haven't really standardized on one language.

      That's because standardizing on a single language is silly for such a broad array of tasks - there's no single language that's good enough for everything. Google's combo of C++, Java and Python, in varying proportions depending on the task at hand, is actually a very good and sensible choice.

      Dynamic typing is a very important enabler of tight code (closures for example).

      That's bullshit. Closures have been present for ages in statically typed languages such as ML and Haskell (which are, by the way, typed much more strictly than C++). In fact, most languages with closures have been strongly typed until recently - historically, Lisp has been the only notable exception.

      It also enables far beta meta programming like unit tests and build automation.

      I don't see what dynamic typing has to do with build automation at all. Unit tests - I assume you mean mocking? - it's actually fairly trivial specifically in C/C++, because you can just link in object files with mocks instead of your real code.

      For statically typed languages with VMs, mocking is done by using VM hooks to intercept calls. For example, TypeMock for .NET can hook into (and therefore mock) absolutely everything, even constructors and non-virtual and static method calls.

      Static typing is the problem, not the solution.

      I guess that's why Objective-C is actually statically typed (though permitting full dynamic dispatch)? I mean, if dynamic typing is so awesome, why not just use Smalltalk?

      Returning to unit tests - ironically, for large projects written in dynamic languages, big parts of their respective unit tests could be thrown out completely if static typing was in place, because they effectively test type safety, only in an ad-hoc way (i.e. if programmer writing the test forgets about some corner case, too bad).

    27. Re:From the article it is obvious by Coward+Anonymous · · Score: 1

      "Because ObjectiveC is a slow shit?"

      Which doesn't matter for 80% of the code you ever deal with. For the code where it does matter you can switch to plain old C (or C++ if you feel the urge).
      In Objective-C you get the best of both worlds. The convenience of an almost script like environment (which is still very fast) for most of what you need to do and a low level C when performance is an issue.

    28. Re:From the article it is obvious by tyrione · · Score: 1
      Objective-C is not Statically typed.

      http://www.usenix.org/publications/library/proceedings/tcl95/full_papers/bogdanovich.txt

      Excerpt:

      A. Overview of Objective-C

      Objective-C is a layer on top of C [6, 17]. It supports classes and message passing paradigms similar to Smalltalk. Describing Objective-C in detail is outside the scope of this paper. Here we give only a brief overview of Objective-C, which is based on the Objective-C FAQ in http://www.yahoo.com/Computers/Languages/Objective_C/. The main characteristics of Objective-C are:

      • It is compiled.
      • It has a dynamic runtime system (objects are dynamically typed). Full type information (name and type information of methods and instance variables and type information of method arguments) is available at run time.
      • Classes and methods can be added (dynamically loaded) at runtime.
      • There is one root class Object from which all other classes inherit. (This is not quite true; other root classes can be defined, e.g., NSProxy in OpenStep.)
      • Method/message syntax is similar to Smalltalk.
      • Unlike in Smalltalk, there is no garbage collection. Instead, reference counting pseudo-garbage collection techniques are typically used.
    29. Re:From the article it is obvious by shutdown+-p+now · · Score: 1

      It has a dynamic runtime system (objects are dynamically typed).

      This is nonsense. For starters, this isn't what "dynamically typed" is - dynamic typing refers to types of bound identifiers (i.e. variables), not types of values. In Obj-C, variables are strongly typed, though you can escape that with "id" (but only for objects - not for primitives such as "int", for example).

      Furthermore, objects in Obj-C are statically typed in a sense that you can change their "isa" field to point to a different class, thus substituting the message receiver. But this doesn't change the value representation (i.e. layout of data fields) of the object, which is immutable, and is definitely part of its type.

    30. Re:From the article it is obvious by ultranova · · Score: 1

      Wait, wasn't it because Apple is a UI/UX genius making polished products that Just Work?

      No, they're marketing geniuses making cool-looking products, for some value of cool.

      --

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

    31. Re:From the article it is obvious by Anonymous Coward · · Score: 0

      If your code runs noticeably slower because of Objective-C method call overhead, you have got the Java disease. Everything is not an Object and shouldn't be.

      Objects are the supreme form of modularity. If your code is actually intertwined in such a way as to need calling methods as functions, the language you should use is called C.

      C++'s half-assed object methods are also painfully slower than C function calls.

      Its syntax sugar for "object-oriented" C function calls doesn't justify pulling all the crap needed for C++ starting with the compiler. g++ is huge and buildin it for such things as cross-compiling is a royal PITA.

      Did you know that clang has just become bootstrapable after many years? Why would that be? Solid Objective-C and C support was available long ago! Maybe because it was written in a crappy mess of a language that not even wizards like them can properly support?

    32. Re:From the article it is obvious by dkf · · Score: 1

      Returning to unit tests - ironically, for large projects written in dynamic languages, big parts of their respective unit tests could be thrown out completely if static typing was in place, because they effectively test type safety, only in an ad-hoc way (i.e. if programmer writing the test forgets about some corner case, too bad).

      The problem with static typing in large projects is that a significant proportion of the code becomes devoted to writing bridging delegates from one type domain to another. This isn't so much a problem with smaller projects because it's often possible to force the use of a single type system, but when things get large that becomes impossible; you just can't coordinate the various developers well enough (typically because some of the code is written externally and can't be changed). Dynamic typing can significantly reduce the amount of glue required, at a cost of compile-time safety; dynamic languages typically enforce run-time checks strictly of course, whereas more static languages use their type system to perform those checks during compilation. (Great when it works, horrendous when it doesn't.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    33. Re:From the article it is obvious by shutdown+-p+now · · Score: 1

      The problem with static typing in large projects is that a significant proportion of the code becomes devoted to writing bridging delegates from one type domain to another. This isn't so much a problem with smaller projects because it's often possible to force the use of a single type system, but when things get large that becomes impossible; you just can't coordinate the various developers well enough (typically because some of the code is written externally and can't be changed). Dynamic typing can significantly reduce the amount of glue required, at a cost of compile-time safety; dynamic languages typically enforce run-time checks strictly of course, whereas more static languages use their type system to perform those checks during compilation. (Great when it works, horrendous when it doesn't.)

      It's not an all-or-nothing proposition, and it is possible to have some middle ground.

      Talking about .NET or Java in particular, if differing types that you need to bridge are all interfaces (or classes inherited from MarshalByRefObject in .NET), then you can create dynamic proxies for them - which have a single dispatch method receiving all method calls on an object, and can forward some (or all) calls to another object with no need to check for each and every method individually. E.g. see this convenience wrapper for .NET (Java API is somewhat simpler, and is trivial to just use directly).

      Such proxies are, of course, not type-checked themselves, and performance-wise they are as slow as any dynamic dispatch. But their clients are still forced to be type-safe, and they only pay the dispatch penalty when they use an object which is proxied; for everything else, it's just the normal cost of vtable dispatch.

      Also, obviously, this is somewhat lengthier than an equivalent implementation in a typical dynamic OO language, but then, IMO, you don't want such things to be too easy to write - they're supposed to be kludges, not something that you write routinely. If such proxying becomes commonplace, it is much harder to understand the working of the code, decreasing its maintainability.

      Furthermore, there are even better approaches to that problem from a static typing perspective. One example were the C++0x (now C++1x...) concepts, and in particular concept maps - the latter allowed you to take any existing type, and map it to any existing concept, without either the type or the concept aware of it; and with members that map directly being mapped automatically. A bit like an outside interface definition. Furthermore, you could have several concept maps between a given type and a concept, each named, and use one or the other in various situations as need be; and even confine them to local scopes.

  10. 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 Anonymous Coward · · Score: 0

      High level != Simple. Ruby is quite high level, but you'd be amazed by the amount of crappy Ruby code out there..

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

    3. 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.
    4. Re:Choices, choices by Anonymous Coward · · Score: 0

      It's not that it's bloated or slow. It's that it's retarded and misdesigned. It's as if C was reinvented with slightly different semantics for no real benefit.

      So, if you present FAQ, I have to counter it with FQA.

    5. Re:Choices, choices by Joce640k · · Score: 0, Troll

      The C++ bashers are an undereducated bunch of whiners. Telling a C++ programmer to go back to C is like telling a C programmer to go back to assembly language, not going to happen. Deciding how to allocate CPU registers to get the tightest loop might be fun for a while but it simply doesn't work when you've got to write a real program.

      Just like C compilers which allocate registers for you (and do a pretty good job!), a C++ compiler makes coding MUCH EASIER and MORE RELIABLE by doing all the micromanagement for you.

      Anybody who thinks "C++ is C with a few extra things" is very, very wrong.

      --
      No sig today...
    6. Re:Choices, choices by LinuxAndLube · · Score: 1

      I don't oppose C++, but You Have To Know What You Are Doing (TM).

      Actually, that's why I like C so much: you don't have to know what you're doing!

    7. Re:Choices, choices by Anonymous Coward · · Score: 0

      Have you read the announcement? No? Come on! it's not like it's an article, is it? OK, OK, this is Slashdot after all...
      Well, the funny thing is that they have agreed to use C++, but they still have to discuss what to do with it!!
      I will repeat it just in case: They don't have any idea of how (or if) it will be of any help.
      Talk about irony...

    8. Re:Choices, choices by daid303 · · Score: 1

      In C you also have to know what you are doing, but the possible options are way less, and they are way less 'side effects' that you need to know.

    9. Re:Choices, choices by Bill+Dog · · Score: 1

      Anybody who thinks "C++ is C with a few extra things" is very, very wrong.

      That and, from TFS:

      ...as many contributors are experts in C, but novices in C++;

      describes pretty much every developer I've ever worked with at C++ jobs.

      --
      Attention zealots and haters: 00100 00100
    10. 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.

    11. Re:Choices, choices by arth1 · · Score: 1

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

      "Can be" isn't a synonym for "is".
      Even though you can make lean C++, it's in the same spirit as how you can make lean barbecue. C++ lends itself to producing bloat, just like a grill lends itself to scorching fatty food.

      Some customers are more concerned with the actual performance than the potential. Unfortunately, far too few. And, unfortunately, customers are also concerned about deadlines and bottom lines. So you cut corners, and hire a few work-for-pizza grad students and H1Bs.

    12. Re:Choices, choices by daid303 · · Score: 1

      I don't like the way how it's put down (it reads like the Kuran, with lot of hate), but it makes many valid points.

      Just to name some:
      -Implicit copy constructors and assign operator bite. You don't expect them, and the STL makes heavy use of them.
      -Name mangling is not specified. Try to mix dlls build with gcc and msvc, fixed that hell? Now, try to build an dll with gcc that can replace a dll build with msvc.
      -Not mentioned in the FQA, but std::string is STUPID. Yeah, it's great to have a string class, it's great that you can overload operators. But if you then build a string class with just = and += as overloaded operators. It's not like we ever do: StringA = StringB + StringC; if (StringA == StringQ)

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

    14. Re:Choices, choices by Anonymous Coward · · Score: 0

      But if you then build a string class with just = and += as overloaded operators.

      What are you on about? std::string does overload operator+ so you can indeed do: StringA = StringB + StringC;

    15. Re:Choices, choices by TheThiefMaster · · Score: 1

      You'll have to imagine the <<

    16. Re:Choices, choices by Anonymous Coward · · Score: 0

      I write a lot of C++ code and like the language. Only when reading the FQA do I feel that someone understands my problems. The FAQ it is polemicising with tries too much to impose a predetermined coding style on you and reads like written by a brainwashed corporate-indoctrinated slave code monkey.

    17. Re:Choices, choices by GooberToo · · Score: 1

      Anybody who thinks "C++ is C with a few extra things" is very, very wrong.

      And that's why I blame the schools. Its exceedingly rare to find a graduate who was not taught C++ is C with new style comments. They then gloss over objects. Fresh grads never seem to know some of the most important C++ fundamentals or aware there are many good books which explain how to avoid the majority of pitfalls.

      If you find you are shooting yourself in the foot with C++, you have no one to blame but yourself. This is called ignorance of the language. Meyers' books really are not that big. Meyers' books are fairly easy reading, and they explain how to navigate or completely avoid the common minefields.

      Time and time again I find those who complain about C++ are simply ignorant. And those who have consistently shot themselves in the foot are both lazy and ignorant. And if their schooling included C++ but did not include at least the fundamentals preached by Meyers, then you did not get your money's worth. Regardless, stop blaming the language.

      This is not to say C++ is perfect. Its not. And contrary to popular belief I do not consider C++ to be much higher level language than C. Its basically C with a lot more features and capability, not to mention a larger standard library. And I believe this is also part of the problem. People believe C++ to be a high level language which should keep them clear of all the land mines. The problem is, C++ provides some high level features but is only slightly higher level than C. As such, the scale of potential mines is much larger.

      Lastly, stop trying to use every feature C++ has to provide. Many of the more advanced C++ features are both powerful and easy to abuse and misuse. Concentrate of the basic language features (classes and templates), learn STL, read a couple of books, and its almost impossible to shoot yourself. Save the more advanced features for a latter date, when you are confident you have mastered the basics.

    18. Re:Choices, choices by Joce640k · · Score: 1

      ]"I do not consider C++ to be much higher level language than C"

      I have to strongly disagree with you there. C and C++ have NOTHING in common apart from the basic syntax.

      There's no equivalent to RIAA in C, there's also no equivalent to stack unwinding or many of the other C++ constructs which are central to good C++ programming.

      I'm currently working on a 200,000 line program which has exactly 9 'delete' statements in it and they're all in definitions of containers and magic pointers. I haven't seen a memory leak for years. Garbage collection? Who needs it?

      Just thinking about using malloc/free/strcpy/strdup/etc. instead of std::string gives me the screaming heebie-jeebies. Same for std::vector vs. C arrays - aaargh!

      --
      No sig today...
    19. Re:Choices, choices by Anonymous Coward · · Score: 0

      Ok, I don't care what you've read about C#, but "lean and mean" is not an accurate statement, at least not when compared to C and C++. I agree that C++ can be extremely efficient, even as efficient as C, but C# is in the same league as Java and other interpreted bytecode languages. Yes, a JIT to cache native instructions helps a lot... but you just can't compare it to C/C++. You can argue the merits of MSIL all you want, but you can't ignore its performance drawbacks. I'm sure benchmark time on a "Hello World" program is relatively similar to C (after the first execution, of course), but anything more complex than that - especially applications that require hardware access - and the native code model spanks it.

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

    21. Re:Choices, choices by j00r0m4nc3r · · Score: 1

      One should never choose a lower level language than necessary only because it is hard core

      However, if the lower level language is punk, it is imperative to choose that one.

    22. Re:Choices, choices by MobyDisk · · Score: 1

      The article argues against C just as hard as it argues against C++. The author seems to want a fully managed environment with a much more capable set of class libraries. Those are valid limitations of C and C++. Java and C# would seem like perfect a fit for him.

    23. Re:Choices, choices by GooberToo · · Score: 1

      I have to strongly disagree with you there. C and C++ have NOTHING in common apart from the basic syntax.

      Considering the languages were purposely designed to be largely compatible squarely means C++ is designed to be a fairly low level language. Its just that on the other end of the spectrum C++ brings to the table additional features which save a lot typing. Regardless, the new mechanisms are still fairly low leveled - yet more feature rich than C.

      There's no equivalent to RIAA in C, there's also no equivalent to stack unwinding or many of the other C++ constructs which are central to good C++ programming.

      Additional features does not make a language high level.

      I'm currently working on a 200,000 line program which has exactly 9 'delete' statements in it and they're all in definitions of containers and magic pointers. I haven't seen a memory leak for years. Garbage collection? Who needs it?

      In what way does that mean its a high level language? I do agree these are aspects commonly associated with high level languages but it doesn't change the fact that the magic is still taking place; albeit beneath the covers. You can do the same thing in C too. Does that suddenly mean C is a high level language too? Of course not.

      If any thing, you post reiterates the virtues of C++ and modern coding styles but it does not elevate C++ to that of a high level language. Though I would say C++ is a higher level language than C++ - just not by much.

      You need to remember the first C++ compilers were actually C front ends. Furthermore, many people have implemented C++ features in C - albeit without the syntactic sugar provided by C++. Though ultimately, I suppose it has more to do with how you define, "high level". After some quick checking, it appears some considering anything above machine language to be "high level".

    24. Re:Choices, choices by GooberToo · · Score: 1

      Additional features does not make a language high level.

      That's a silly statement at face value. I hope you'll look beyond the simplicity of that statement at face value. Which is to say, this is why C++ is a higher level language than C++ yet is still a relative low level language fairly compatible with C.

    25. Re:Choices, choices by Hurricane78 · · Score: 1

      And Einstein was wrong.
      The quote already is a wonderful example of what happens when things are made simpler than they should.
      Actually he should have said: Make things as efficient as possible. Period.
      Because “should” refers to the actual goal. Which is efficiency.
      And that’s why “KISS” is so retarded. It already fell for its own fallacy. From that point on, there is nothing you can do anymore. You already fucked up. The basis of the whole logic is rotten.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    26. Re:Choices, choices by Anonymous Coward · · Score: 0

      FQA link is sententious garbage. It truly achieves the Pauli criterion, it isn't even wrong. Although its general message is correct. C++ is indeed not Java.
      --
      phunctor

    27. Re:Choices, choices by trialcode · · Score: 1

      Oh, come on! How old are you? 18 tops? Calling everyone who disagrees with you undereducated whiners is going to take you nowhere in life.

      C++ does a lot of stuff under the covers and if you don't understand exactly what it's doing it's going to come back and bite you badly. What I (and a lot of other people) am arguing is that it's a bad trade-off, that it's easier to do the chores yourself than to make sure C++ only does exactly what you want it to.

      And finally we find something we agree on.
      Only that's what a lot of people, including the GCC folks, are pretending. That it's nothing but C with extra sugar on top.

    28. Re:Choices, choices by Angst+Badger · · Score: 1

      The gist of the referenced FQA seems to be a rant about how managed code is good and unmanaged code is bad, not very cleverly disguised as a expose of well-known problems with C++.

      --
      Proud member of the Weirdo-American community.
    29. 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!
    30. Re:Choices, choices by Anonymous Coward · · Score: 1, Insightful

      Here, here, my good man. I do exactly the same thing as you. C++ is great as an expanded C. I use it to simplify my code (yes, that's right) and to leverage the object features of C++. I keep to a minimum the use of the abstraction-y bits such as templates, inheritance chains, and overloading precisely because things can creep in that are hard to catch at a glance. I figure that if somebody can't look at an individual function / method and see exactly what is supposed to happen, then you've just created something that will never be properly peer reviewed. Nobody wants to have to work their way back through 6 super calls to determine what the given state of a member is or if '+' really means add in x = y + z.

    31. Re:Choices, choices by ckaminski · · Score: 1

      The major issue I have with Java is the GC - at some point, especially when dealing with THOUSANDS of objects, the GC is going to abruptly stop your application as it tries to deal with the allocation nightmare. It's gotten better over the years, but it's not gone away.

    32. Re:Choices, choices by Anonymous Coward · · Score: 0

      As can C

    33. Re:Choices, choices by thechao · · Score: 1

      I've never bothered to read the FQA; however, this time, I decided to jump in. It certainly is a lot of vitriol and hyperbole, isn't it? I'm not exactly sure what the author(s?) want, but just from the "summary" it sounds like he would like to use a strongly, statically-typed, garbage-collected language (with "management") that has a number of "high level, built in" types with a reflection system and a module system, etc. I'm certain there are many (supposedly well-implemented; btw, unless it is machine verified C, OCaml, or SML, the language implementation has bugs) languages with those properties; why doesn't he use one of those?

      The weird part of the FQA is the feeling I get that he thinks C++ is somehow flawed as a language due to its cruft. However, from a type-system or systems-programming point-of-view it doesn't seem to have an practical (or theoretical) problems. Is he claiming that C++ is not turing complete? That it doesn't compile to efficient code? That it is impossible to write large applications in the language?

    34. Re:Choices, choices by mini+me · · Score: 1

      That is because people come with experience from languages like C, Java, and PHP and try to write Ruby code in the same style. It is easy to write good code in Ruby once you take the time to learn how to design your code to fit Ruby's programming model.

    35. Re:Choices, choices by mini+me · · Score: 1

      Just thinking about using malloc/free/strcpy/strdup/etc. instead of std::string gives me the screaming heebie-jeebies. Same for std::vector vs. C arrays - aaargh!

      There is no reason why you cannot have vectors and strings in C. There are good reasons to use C++, but it seems kind of silly to choose it just because of its richer standard library when one can easily include libraries to do the same in their C code.

    36. Re:Choices, choices by wjc_25 · · Score: 1

      The first example (which is shorter if you have "using namespace std," of course) of cout seems pretty reasonable to me. I can look at that code and, with my fairly basic knowledge of iostream, immediately see what's going on. For the second it's far less clear.
      People will always disagree on whether clarity or concision is preferable; I don't think this is a "one right answer" sort of problem.

    37. Re:Choices, choices by TheThiefMaster · · Score: 1

      Basically my point was that you shouldn't need to set it back to decimal after printing something in hex, and setting the fill character should be part of the width setting.
      My preference to using temporaries instead of state changers is purely from having to track down bugs caused by things misusing state. e.g. not specifying std::dec when wanting to print in decimal, and something else that prints in hex not changing the state back to decimal. The same goes for fixed width printing and god knows what else.

    38. Re:Choices, choices by Anonymous Coward · · Score: 0

      Are you claiming that C++ is not a flawed language? I don't think even the staunchest defender of C++ would go that far if they are trying to stay honest.

    39. Re:Choices, choices by Joce640k · · Score: 1

      C++ allows you to work at a MUCH higher level of abstraction than C.

      Sure, it doesn't force you, but if that's your only argument then you're missing the point.

      --
      No sig today...
    40. Re:Choices, choices by TheNetAvenger · · Score: 1

      It really comes down to people not understanding object based programming.

      Even the basic concepts of C++ are simple object programming concepts and without a full understanding of object programming it becomes a cumbersome and poorly implemented set of code, especially when implemented by C programmers that have don't think in terms of objects or understand the relationships.

      I have also listened to smart developers complain about C#, when they don't have a clue of what the difference is between an object based language like C++ and what an object oriented language like C# offers.

      What surprises me the most is that literally 20 years ago our university was strong in defining the differences, strengths and giving a full understanding of object based and object oriented models not only in programming but also with regard to IPC mechanisms and even OS design theories.

      Looking back, I think our university was more cutting edge than I realized, as over the years it is hard to find even mediocre training/classes in object based design even today.

      It also seems to come from the OSS world were object based/oriented concepts are the red headed stepchild; which would also explain the complete lack of understanding in the OSS world of object based/oriented OS technologies like NT and how beneficial these designs are in an OS.

      20 years later we will still be waiting for the next generation of OS and programming model designs and all the new 'kiddies' then will be digging out XNU/Darwin and Linux as the great new OS concept, bandaids and all to make them work just like I have watched every 'kiddie' do with Linux and XNU over the past 15 years.

    41. Re:Choices, choices by DeKO · · Score: 1

      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.

      You mean you changed the class definition by adding pointers, without worrying about maintaining the class invariant (which is to protect those pointers) and blame the language? You might want to learn a bit more about OO programming.

      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.

      I'm sure you enjoy doing str.append("."); in your favorite language with no operator overloading at all. Even funnier must be 4 + 5 and 4.2 .+ 5.3. Humans are, after all, context-free, and can't possibly use the surrounding code (i.e. the whole line, instead of a single token) to figure out what the code does.

      References: references aren't what most people think of as references.

      Most people I know are aware that references are not smart pointers. Why would anyone think that? They are just like pointers that can't be changed. The only unusual usage is when you use them to keep temporary objects alive. Remind that C99 had to introduce a new keyword, restricted, to mitigate the aliasing problems that always hurt the optimizer; by using references instead of pointers you solve almost all of these problems.

    42. Re:Choices, choices by murdocj · · Score: 1

      None of the things I cited (references being syntactic sugar on top of pointers, default assignment operator causing bugs, or the difficulty of coming up with decent overloaded operators) have anything to do with understanding OO. It's possible to be perfectly comfortable and good at object oriented programming, and still fall into a C++ trap. In fact, if you were comfortable with Java, you would certainly not expect a C++ reference to become invalid, just because you inserted another element into a container.

    43. Re:Choices, choices by shutdown+-p+now · · Score: 1

      C# as a language is not inherently slower than C, if you stick to the subset of C# which corresponds to C. I.e. if you don't use classes and objects and delegates and bound-checked arrays, but only structs and raw pointers.

      In practice, real-world implementations are still slower, because the JIT doesn't optimize as well as a static compiler would (and that is largely because it doesn't have the luxury of spending several minutes doing e.g. deep inlining).

      However, it is perfectly possible to compile MSIL to C, and even a moderately complex C# program - again, so long as it's written "on the same level" as one in C - would produce MSIL which, when translated to C, would be semantically identical to hand-written one; and if compiled with the same compiler, having same performance.

      Of course, as soon as you use C# as it is intended to be used - as a high-level OO language with garbage collecting etc - any performance parity evaporates. There's no way around things such as array bound checks and heap allocations adding overhead.

    44. Re:Choices, choices by shutdown+-p+now · · Score: 1

      Java has had background GC for a while now, and .NET has got it in a recent release.

    45. Re:Choices, choices by Anonymous Coward · · Score: 0

      All thing you said are newbies mistakes... not the kind of things that would bother someone that is programing a C++ compiler.

    46. Re:Choices, choices by Anonymous Coward · · Score: 0

      Bad Typeface; DNR.

    47. Re:Choices, choices by sim82 · · Score: 1

      don't forget that "printf("0x%08x\n", x);" is still completely valid c++ code. The fact that some people prefer iostreams is no reason eveyone should use them (c++ is not pre 1.5 java!).

    48. Re:Choices, choices by GooberToo · · Score: 1

      No, that's not my argument. And as for the "abstraction", that's because you're using objects. That too can be done in C but is a PITA.

    49. Re:Choices, choices by murdocj · · Score: 1

      You mean you changed the class definition by adding pointers, without worrying about maintaining the class invariant (which is to protect those pointers) and blame the language? You might want to learn a bit more about OO programming.

      When a change to the program can break a piece of code that the compiler conveniently wrote for me, yes, of course it's a language problem. Given the number of articles, web pages and C++ books that prominently mention workarounds for this issue, I'm clearly not alone in considering this to be a trap.

      I'm sure you enjoy doing str.append("."); in your favorite language with no operator overloading at all. Even funnier must be 4 + 5 and 4.2 .+ 5.3. Humans are, after all, context-free, and can't possibly use the surrounding code (i.e. the whole line, instead of a single token) to figure out what the code does.

      Overloading numeric types is a nice strawman, and conveniently lets you ignore the stream operator issue that I mentioned. Well done.

      Most people I know are aware that references are not smart pointers. Why would anyone think that? They are just like pointers that can't be changed. The only unusual usage is when you use them to keep temporary objects alive

      Again ignoring the issue I brought up. I'll make it a little more explicit. Take a reference to an element of a vector. Add on to the vector until the vector is reallocated. The "reference" now points to garbage. No temporary objects involved. I can guarantee you that anyone familiar with other OO languages would be quite surprised by that behavior.

    50. Re:Choices, choices by Homburg · · Score: 1

      The C++ standard library containers are type-safe and automatically de-allocate memory when they go out of scope. Neither of those features are possible in C.

    51. Re:Choices, choices by Anonymous Coward · · Score: 0

      As sim82 said, a not insignificant amount of people use standard stdio rather than iostreams. It is faster, when that small boost is needed.

      Anyway, I'm not an expert with iostreams (I think it's the worst designed component of SC++L), but you should be able to define your own stream manipulator do exactly what you desire (in identical code form).

      If you're actually saying printf is superior, I'll add one more thing: printf's main problem is that it isn't typesafe. For a language designed to be secure (sometimes in retrospect), this is a killer. C++0x's variable argument template support should enable a typesafe printf, however.

    52. Re:Choices, choices by Anonymous Coward · · Score: 0

      What are you on about? std::string does overload operator+ so you can indeed do: StringA = StringB + StringC;

      To note, also with a stupidly absurd amount of temporaries, so doing something like string A = B + C + D + E is extremely slow. But C++0x's move semantics handily fixes this issue.

      And to address remainder of GP's post:

      Implicit copy constructors and assign operator bite. You don't expect them, and the STL makes heavy use of them.

      If you mean implicit conversion, you can avoid this with the explicit keyword. Also, check out boost::implicit_cast for better-documented and designed code -- it's basically a less powerful static_cast. It should be in the next C++ standard, following C++0x.

      If you mean STL's use of temporaries... again, move semantics. MSVC10's STL implementation already has move constructors/operators defined for most STL classes. Copying a vector temporary is no longer a massive operation.

      Name mangling is not specified. Try to mix dlls build with gcc and msvc, fixed that hell? Now, try to build an dll with gcc that can replace a dll build with msvc.

      It isn't a high point (allocation boundaries are another thing you have to watch out for). Anyway, it's not too terribly complicated to work around, with enough effort. AFAIK, this is the main reason for COM's prevalence today.

    53. Re:Choices, choices by jlechem · · Score: 1

      I don't know about Java but C# does this. Supposedly it's not noticeable but in a large Server app we're seeing massive amounts of time being spent in GC. Some of this is object churn and burn, but to stop all code execution while GC runs is a bad design IMO. .Net 4.0 is now supposed to be different and does differential GC in the background all the time so your apps don't stop running completely while the GC runs.

      --
      Hold up, wait a minute, let me put some pimpin in it
    54. Re:Choices, choices by Anonymous Coward · · Score: 0

      I agree on your points.

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

      Yeah, they flat memcpy all the instance slots without batting an eye but don't nag about uninitialized member variables (how would uninitialized member variables ever be useful?). Boggles the mind, doesn't it?

      And the supposed way to prevent this is to declare your own constructor as private in the class declaration and then _don't implement it at all_. No, really, I'm not kidding.

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

      That was the very first case of asshattery, not overloading.

      The first case of overloading is:
      long operator+(int a, int b) {
          return you_know_what_mathematicians_mean_when_they_say_add_and_no_it_isn't_allowed_to_overflow(a, b);
      }

      long long operator+(long a, long b) {
          return you_know_what_mathematicians_mean_when_they_say_add_and_no_it_isn't_allowed_to_overflow(a ,b);
      }

      Also,
      double operator/(int a, int b) {
          return you_know_what_mathematicians_mean_when_they_say_divide_and_no_it's_not_an_integer(a, b);
      }

      Pretty natural. That's why it isn't like that in C++.

      On the other hand, I wonder what the first person was thinking who was doing something akin to this:
      ostream& operator+(ostream& o, long b) {
          you_know_do_something_totally_unexpected_here_because_boy_that_makes_sense(o);
          return o;
      }

    55. Re:Choices, choices by Anonymous Coward · · Score: 0

      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.

      You sound like a C programmer. References are far more limited than pointers, making them less error-prone. Yes, as in your example, freeing memory that it refers to will cause the reference to become invalid. But there are other ways you can break pointers that don't happen with references. References can't be null, can't be reassigned, and can't refer to other references.

    56. Re:Choices, choices by DeKO · · Score: 1

      When a change to the program can break a piece of code that the compiler conveniently wrote for me, yes, of course it's a language problem. Given the number of articles, web pages and C++ books that prominently mention workarounds for this issue, I'm clearly not alone in considering this to be a trap.

      Do you realize that in almost every language you can break the whole program through a small change? Who is this different than say creating an infinite loop by adding a ";" after a while (...) expression?

      Overloading numeric types is a nice strawman, and conveniently lets you ignore the stream operator issue that I mentioned. Well done.

      It is not a strawman. Operators are overloaded all the time on Mathematics. Words are overloaded in human language. Why is overloading in a programming language so hard to accept?

      Again ignoring the issue I brought up. I'll make it a little more explicit. Take a reference to an element of a vector. Add on to the vector until the vector is reallocated. The "reference" now points to garbage. No temporary objects involved. I can guarantee you that anyone familiar with other OO languages would be quite surprised by that behavior.

      It is a characteristic of the std::vector then, not the reference's. The same happens if you hold a pointer or an iterator to an element of the container. The standard clearly states that references and iterators to elements of a std::vector might be invalidated after reallocations. Use std::list and this problem goes away. There is no data structure that has no downsides; it is not C++'s fault.

    57. Re:Choices, choices by Josef+Meixner · · Score: 1

      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.

      First, why is it causing a bug? Because you used a pointer to mean ownership and deallocate the object behind it in the destructor? If the class in question is not managing the object behind the pointer the default assignment operator is correct. But yes, that is one of the things you have to learn about C++. But how is that different from C? If I add a pointer to a struct and make a copy of that struct somewhere in the code I have exactly the same issue.

      The use of << and >> was in my eyes just a poor choice. It would have been possible to use ".print(...)" in exactly the same form, so writing stream.print(3).print(" something"). I consider it an abuse and honestly I need way too few of them to make saving the few keystrokes worth the strange look. Is anybody really using a significant amount of those operators so that the few keystrokes are important?

      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.

      Can you back your claim of "most people"? In a language without garbage collection you cannot have fixed references to value types. It would be way too costly to implement, if you need it you have to store pointers in your vector and pass those pointers. References are not 'pointers with syntactic sugar' as they are much more limited, e.g. there is no NULL-reference and currently a reference can only be bound to an lvalue and not to an rvalue. Even with the addition of rvalue references and reference collapsing in the coming standard you have to explicitly request a rvalue reference. Also references explicitly show, that the called function will not do any thing like release the object, something you can't be sure of a function taking a pointer.

    58. 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!
    59. Re:Choices, choices by Anonymous Coward · · Score: 0

      Thanks for that post, it really put my fears to rest when I read this:

      The more "exotic" bits of C++ (RTTI, exceptions, virtual inheritance,
      templates, etc.) all involve the compiler doing a lot more implicit
      generation of data structures and code, including, in some cases,
      implicitly making data structures bigger. I think these techniques are
      valuable when used appropriately, but I wouldn't propose using them in
      GCC soon. It is easy to mis-use them and for them to have unintended
      consequences.

      These things are where the goblins hide on non-x86 embedded platforms. It's gotten better, but I don't want to waste even a day trying to track such problems down because of the _compiler_.

    60. Re:Choices, choices by shutdown+-p+now · · Score: 1

      Yes, and it's done where the analyzer can figure out that it doesn't affect semantics. But there are still many cases where it cannot figure that out. Yes, in Sun JVM as well (though it is somewhat better at it).

    61. Re:Choices, choices by maxwell+demon · · Score: 1

      Implicit copy constructors and assign operator bite. You don't expect them, and the STL makes heavy use of them.

      If you don't expect them, you shouldn't claim to know C++.

      Name mangling is not specified. Try to mix dlls build with gcc and msvc, fixed that hell? Now, try to build an dll with gcc that can replace a dll build with msvc.

      It's also not specified with C (and if you think there's no name mangling in C: There were DOS compilers which preceded all global symbol names with an underscore, in order to avoid assembler conflicts with register names). It's just that on every platform today, there's a separate ABI standard or de-facto-standard for C (e.g. the psABI), and since today the OS interface is generally in C, any compiler has to follow the platform ABI. The same is not (yet) true for C++, but there are already standardization efforts (for example, while GCC in the past used a homegrown ABI, it now uses a standardized ABI which is also used by other compilers [while it's formally only an Itanium ABI, GCC uses the non-Itanium specific parts of it also for other platforms]).

      Not mentioned in the FQA, but std::string is STUPID.

      Agree here: std::string is not well designed. I'm pretty sure that if it were designed today, it would be designed differently.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    62. Re:Choices, choices by murdocj · · Score: 1

      But how is that different from C? If I add a pointer to a struct and make a copy of that struct somewhere in the code I have exactly the same issue.

      Exactly the point: the difference in C++ the code doing a bitwise copy of the structure is automatically generated by the compiler, and not visible in the source code.

    63. Re:Choices, choices by Anonymous Coward · · Score: 0
      There's no equivalent to RIAA in C, there's also no equivalent to stack unwinding or many of the other C++ constructs which are central to good C++ programming.

      I'd prefer to keep the RIAA out of C. Or did you mean RAII? Oh, and setjmp/longjmp have been doing stack unwinding for years. In summary, you don't know C and you don't know C++.

    64. Re:Choices, choices by Anonymous Coward · · Score: 0

      To paraphrase Einstein [wikiquote.org]:

      Make things as simple as possible, but not simpler.

      Something tells me Einstein was one of those guys that never backed anything up.

    65. Re:Choices, choices by murdocj · · Score: 1

      It is not a strawman. Operators are overloaded all the time on Mathematics. Words are overloaded in human language. Why is overloading in a programming language so hard to accept?

      Overloading numeric operators is a strawman. It's the obvious case where the operator works exactly as you expect. It's also the case that is already built into most language. How many times have you implemented a new numeric type?

      As I pointed out, the operators for streams were chosen because they were obscure, because most of the operators had intuitive meanings that didn't match the overload. Which is the core problem with overloading operators.

    66. Re:Choices, choices by Anonymous Coward · · Score: 0

      Bloated, Slow, and much more difficult to maintain an object.

      Object oriented C++ is great, for non-time critical development. I would suggest that we would find a 15 to 30 percent reduction in kernel execution speed should it be converted to C++.

      On the other-hand, for non-time critical applications, and particularly for graphics manipulation, I say, why not.

      A judicious choice is what I think will eventually prevail.

    67. Re:Choices, choices by soppsa · · Score: 1

      As can C# (which I'm mostly using right now).

      You lost me there. Sorry, not sure anything about that runtime hell is 'lean and mean'.

    68. Re:Choices, choices by GooberToo · · Score: 1

      I've wiped my tail end with material which is far more accurate and less deserving than the provided link. As another poster replied, its basically a bunch shit for ignorant people to troll and sprew. Made worse, people who don't know any better may belive the truthful elements of his FAQ are the proper way to do things when in fact, he consistently picks the dumbest, worst possible way to do anything in C++, combined with half truths and boldface lies, and then deduces that C++ is a terrible language.

      The only thing that FAQ proves is the author is an absolute fucking idiot.

    69. Re:Choices, choices by GooberToo · · Score: 1

      ...well known problems for people who don't know any better. That's why so many books have been written which simply explain, don't do the stupid stuff which the FQA author espouses. In fact, one could easily argue his FQA is the antithesis of a learned coder. Which raises the question, why does someone who is completely ignorant believe they are a subject matter expert? The short answer is, they are a delusion idiot or pushing an agenda.

      My money is on him being a Java or C# developer.

    70. Re:Choices, choices by David+Greene · · Score: 1

      No, longjmp does not unwind the stack. setjmp saves a machine context at a program point and longjmp jumps to that point and restores the machine context. Using setjmp/longjmp in C++ is deadly because destructors will not be called.

      --

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

    1. Re:Incorrect headline by jimmydevice · · Score: 1

      When using C++, C is always there. C++ can be rightly ignored. Screw it's contextual syntax.

    2. Re:Incorrect headline by Anonymous Coward · · Score: 0

      Screw it's contextual syntax.

      In fact, screw syntax! Yeah!

    3. Re:Incorrect headline by FreakyGreenLeaky · · Score: 1

      Exactly. Do it in Perl.

    4. Re:Incorrect headline by mini+me · · Score: 1

      While C++ shares many of the same characteristics as C, it is its own language. You can write valid C code that will not compile under a C++ compiler.

      Perhaps you were thinking of Objective-C, which is a strict superset of C? Any valid C code can be compiled with an Objective-C compiler.

    5. Re:Incorrect headline by ConceptJunkie · · Score: 1

      AIUI, the latest C standard adds stuff that is not in C++98. But using C++ is now merely an option, not a requirement. It probably won't be used much, at least at first. But who knows, maybe some of that serious juju coming in C++1x will allow for writing some amazing tools more easily and quickly.

      --
      You are in a maze of twisty little passages, all alike.
  12. AVR-GCC by dohzer · · Score: 1

    Will this feed through to things like AVR-GCC for Atmel AVR 8-bit microcontrollers?
    I wonder what changes in performance we would see.

    http://winavr.sourceforge.net/

    1. Re:AVR-GCC by Anonymous Coward · · Score: 0

      AVR-GCC can already compile C++, like all other GCC versions (AFAIK). The language in which the compiler itself is written won't affect users directly, unless it results in flaky behavior.

      And frankly, it doesn't sound like a C++ guru convention is going on over there.

  13. 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 Anonymous Coward · · Score: 0

      Wrong. GCC has a C compiler, a C++ compiler, a Object-C compiler, a Java-Compiler, a Fortran compiler and a Ada Compiler.... and also libraries and extra tools useful for those languages.

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

    3. Re:The devs don't know C++?? Its a C++ compiler! by Homburg · · Score: 1

      GCC is both. The GNU C Compiler is a C compiler; the GNU Compiler Collection includes the GNU C Compiler, G++ (a C++ compiler), and maybe various other compilers (I can't remember whether GJC for Java, GNAT for ADA, or anything else, are part of GCC); these compilers share a lot of their functionality (abstract syntax trees, code generation), with the separate languages being multiple front-ends for a language-agnostic back-end. So it wouldn't be surprising if a number of the developers of this back-end didn't know C++.

    4. Re:The devs don't know C++?? Its a C++ compiler! by Anonymous Coward · · Score: 0

      What's the hell are you talking about ?!

      GCC, the GNU Compiler Collection

      The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Java, and Ada, as well as libraries for these languages (libstdc++, libgcj,...).

    5. Re:The devs don't know C++?? Its a C++ compiler! by bgarcia · · Score: 1
      Be kind.

      Parent is obviously one of the GCC developers.

      --
      I'm a leaf on the wind. Watch how I soar.
    6. 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...

    7. Re:The devs don't know C++?? Its a C++ compiler! by Ed+Avis · · Score: 1

      gcc (or any compiler) has several stages; as a minimum a front-end and a back-end. It's quite possible that people hacking on the back-end, generating optimized machine code for particular processors, know nothing of C++ or Ada or Fortran or the other languages for which gcc has a front-end.

      --
      -- Ed Avis ed@membled.com
    8. Re:The devs don't know C++?? Its a C++ compiler! by multipartmixed · · Score: 1

      Or, you can be an excellent English teacher, who knows how to parse a sentence into it's component pieces, but haven't the slightest clue as to how to write a novel, or a play.

      There is a LOT more to writing good C++ code than learning the grammar. Any decent coder can jump the C to C++ grammar ladder in a few days. It takes a lot longer than that to be able to effectively express ideas in the language, using idioms that are appropriate, backed by K-lines of experience that teach you what works and what doesn't.

      --

      Do daemons dream of electric sleep()?
    9. Re:The devs don't know C++?? Its a C++ compiler! by Hurricane78 · · Score: 0

      You contradict yourself. First you say, GCC is not a C compiler.
      Then you say that GCC is a compiler for C, C++, Java, etc. Which means GCC IS (also) a C compiler.

      Learn the concept of sets and subsets please.

      --
      Any sufficiently advanced intelligence is indistinguishable from stupidity.
    10. 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.
       

    11. 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:The devs don't know C++?? Its a C++ compiler! by Anonymous Coward · · Score: 1, Insightful

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

      Given the GNU Project's fetish for "cleverly" misleading names, I don't think it's fair to call the GP "confused" when he/she was referring to gcc and could have simply decided to capitalize the initialism like a sensible person would. gcc is indeed a compiler that does not compile C++; g++ is a compiler that does compile C++; both are part of the software suite that the GNU Project sadistically decided to name GCC.

    13. Re:The devs don't know C++?? Its a C++ compiler! by FBSoftware · · Score: 1

      Actually, GCC's Ada compiler (GNAT) is written almost entirely in Ada. I think it was originally bootstraped in the early 1990s using a different Ada compiler.

    14. Re:The devs don't know C++?? Its a C++ compiler! by Homburg · · Score: 1

      Learn the Axiom of Foundation please.

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

      Ah, I didn't know that. I always believed a C compiler was all you needed to bootstrap all of GCC.

      Is Ada the only counter example?

    16. Re:The devs don't know C++?? Its a C++ compiler! by Per+Abrahamsen · · Score: 1

      The only one I know of.

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

  15. 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 Renegade88 · · Score: 1

      What do you mean, "return of bad old days"? Have you actually viewed GCC code? It's still full of #defines.

      Conversely, I'll keep rooting for LLVM because it's not GPL licensed.

    2. Re:Finally! by Anonymous Coward · · Score: 0

      I once used a C compiler on CPM which was a shell script. You could see it step through the preprocessor, code generator and assembler.

    3. Re:Finally! by serviscope_minor · · Score: 1

      Bad old days: did you ever try to write portable C or C++ code in the (say) mid 90's on UNIX? Or more recently on embedded platforms.

      They all sucked. Now most of them use GCC, life has got a whole lot better.

      That is what I mean by the bad old days.

      And I'll keep rooting for GCC because it is under the GPL. It acieved what Stallman set out to do, make life one whole heckuva lot better for end users (i.e. me, the schmuck writing code) of the compiler in this case through the use of Free software. So yeah. I like GCC being under the GPL.

      --
      SJW n. One who posts facts.
    4. Re:Finally! by Anonymous Coward · · Score: 1, Informative

      You're not parsing correctly. He's talking about app/whatever code written using tons of #defines to work around bugs and features in different vendors compilers.

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

    7. Re:Finally! by trialcode · · Score: 1

      The C++ I've learned and am trying to forget does a hell of a lot more than standardize the OOP boilerplate, give C++ a finger and it'll eat you and your family.
      They will spend all of their time arguing about const &this and virtual destructor that instead of solving real problems until nobody really cares anymore.
      The life so short, the language fucking impossible to learn.

      If they feel they've got to improve their architecture, fine, do that. There's nothing magical in C++ that will make their code better, only more complex.

      And about LLVM and the bad old days, that's not really what's happening.
      What *is* happening is that the most commercial and proprietary company I know of is using it's resources to develop open source compiler technology.

    8. Re:Finally! by Anonymous Coward · · Score: 0

      Yes, supporting only one bad compiler instead of many makes things much easier.

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

    10. Re:Finally! by Joce640k · · Score: 1

      IOW ... you haven't bothered to learn C++ so you're relying on anti-C++ dogma in your rants. In other contexts that would be called 'religion'.

      ]"The life so short, the language fucking impossible to learn."

      Impossible for YOU, maybe.

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

    12. Re:Finally! by Joce640k · · Score: 1

      All those constructs were added to C++ for a reason.

      C programmers usually end up reinventing them, badly.

      --
      No sig today...
    13. Re:Finally! by Anonymous Coward · · Score: 0

      How are you supporting gcc? Are you donating money? Maybe you're a core gcc developer? Or you write documentation? Or do you just post on slashdot?

    14. Re:Finally! by mini+me · · Score: 1

      Wait, people were doing OOP in C?

      Of course. Consider the following:


      typedef struct Foo
      {
          char *name;
      };

      Foo * foo_new()
      {
          Foo *foo = malloc(sizeof(Foo));
          foo->name = NULL;
          return foo;
      }

      void foo_free(Foo *foo)
      {
          free(foo->name);
          free(foo);
      }

      void foo_set_name(Foo *foo, const char *name)
      {
          free(foo->name);
          foo->name = strdup(name);
      }

      int main(int argc, char **argv)
      {
          Foo *foo = foo_new();
          foo_set_name(foo, "John Smith");
          foo_free(foo);

          return 0;
      }

      That is really all OOP is at its basic level. OOP languages add syntax sugar to make accessing objects more convenient, but you most certainly can write object oriented C. You can even implement inheritance and all those other cool OOP features in plain old C. C++ was originally written as a preprocessor that converted C++ code to C before compilation.

  16. As everyone forgot EGCS vs GCC back in Linux 2.x by Anonymous Coward · · Score: 0, Insightful

    Damn I remember how everyone was fighting with different versions of slightly different compilers. Kernels of Linux back in 2.0 and 2.2 were a mess, and I was maintaining Caldera OpenLinux distributions numbered 2.1 to 2.3 (those aren't Linux kernel versions, but box product revisions). Yeah, I was the sole user that Darl McBride prided himself on just because OpenLinux was specialized for the better IPX network share support that my Fortune 10k company needed. Thankyou PJ and Groklaw sandwitchcraft for the smoke and mirrors.

  17. 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.
    1. Re:C++ flame wars by elrous0 · · Score: 1

      Well Java would visit his uncle instead, if he would hire a garbage service to clean up all that shit that's built up in front of his house.

      --
      SJW: Someone who has run out of real oppression, and has to fake it.
    2. Re:C++ flame wars by kestasjk · · Score: 1

      My uncle is an industry standard too

      --
      // MD_Update(&m,buf,j);
  18. Nope by Weezul · · Score: 1

    They'll implement the new machine code generation routines in C++ just like now, and then cross compile gcc.

    --
    The Christian religion has been and still is the principal enemy of moral progress in the world. -- Bertrand Russell
  19. Rubbish by Viol8 · · Score: 1

    $ g++ -v
    Reading specs from /usr/lib/gcc/i486-slackware-linux/4.3.3/specs
    Target: i486-slackware-linux
    Configured with: ../gcc-4.3.3/configure --prefix=/usr --libdir=/usr/lib --enable-shared --enable-bootstrap --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix --enable-checking=release --with-system-zlib --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --with-gnu-ld --verbose --with-arch=i486 --target=i486-slackware-linux --build=i486-slackware-linux --host=i486-slackware-linux
    Thread model: posix
    gcc version 4.3.3 (GCC)

    That looks like gcc to me

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

  21. 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 Anonymous Coward · · Score: 0

      Well, there is already one sick part of C++ in using something as simple as namespaces and simple OOP: C++ namemangling, which is horribly spec'ed and can lead to huge problems. For example a project of the size of gcc might suffer quite a noticable slowdown on startup (dynamic linking) because of those freaky long mangled names.

    2. Re:Safe subset by serviscope_minor · · Score: 1

      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.

      There is nothing special about operator overloading. In any good language, you get used to thinking about operators as functions with a funny syntax. That removes all the mystery. Sure it is not good to overload everything up to the eyeballs, but one could say that in C it is easy to make millions of silly macros or functions.

      Besides, GCC makes quite heave use of GMP which is the *IDEAL* candidate for operator overloading.

      --
      SJW n. One who posts facts.
    3. 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...
    4. Re:Safe subset by Joce640k · · Score: 1

      Yes...one of the BIG wins in OO programming is that each class works like a mini namespace. It seems like a minor detail to the C++ bashers but in practice it removes a huge burden from the programmer - all function names can be short and logical.

      --
      No sig today...
    5. Re:Safe subset by Skapare · · Score: 1

      Any language can be abused. GCC does that a lot with C already and it is widely known (GLIBC is worse, BTW). The issue might well just be that with this fact known, they want to avoid having that problem just get worse with C++.

      --
      now we need to go OSS in diesel cars
    6. Re:Safe subset by Interfacer · · Score: 1

      Then again, mangled names have their place to resolve overloaded method names.

    7. Re:Safe subset by pauljlucas · · Score: 1

      For example, operator overloading is great if used judiciously, but if used badly it can make the code a mess.

      Ordinary functions are great if used judiciously, but if used badly it can make the code a mess. Consider:

      int add( int a, int b ) {
      return a - b; // fooled you!
      }

      Any language facility can be misused.

      --
      If you reply, do so only to what I explicitly wrote. If I didn't write it, don't assume or infer it.
    8. Re:Safe subset by MobyDisk · · Score: 1

      The new operator is what sold me on C++, a long time ago.

      #define DESIRED_ELEMENTS 50

      int * arrayOfInts = (int *)malloc(DESIRED_ELEMENTS * sizeof(int));
      int * arrayOfInts = new int[DESIRED_ELEMENTS];

      The second one is a lot less error prone. Even the macro variations in C are still not as clean.

    9. Re:Safe subset by physicsnick · · Score: 1
      There are many problems with your example.
      • You can't do non-trivial initialization in the constructor because initializer syntax is not turing complete. Most C++ style guides (such as Google's) suggest using a separate init() function, so it isn't really less lines of code.
      • A constructor can't fail without throwing an exception. Assuming you don't allow exceptions, your class now needs an internal dead state. This is the case even if you use a separate init(), because the destructor needs to know whether init() was successful (unless of course you use a separate destroy(), making this pointless.)
      • A destructor can't fail at all. There is no way to indicate failure; you can't throw an exception because the destructor might be called during stack unwinding from another exception. What if the destructor fails to flush a buffer? The C version can simply return a boolean to indicate this.
      • There is no way to indicate that MyClass should not be inherited, so to allow deletion through a base class pointer (a requirement to satisfy the Liskov substitution principle), your destructor should be virtual. This adds overhead to the class itself, and adds a lot of overhead at the call site if the runtime type cannot be statically inferred.
      • You now need implement (or at least declare private) copy constructors and operator=. Developers expect C++ objects to be copyable, and standard containers require it.

      Don't you see what is going on here? Even the most trivial feature of C++, constructors, are horribly ridden with complications. C++ is a language of never-ending surprises, gotchas, land mines. It's a trap.

    10. Re:Safe subset by petermgreen · · Score: 1

      Sure it is not good to overload everything up to the eyeballs, but one could say that in C it is easy to make millions of silly macros or functions.
      Lets first consider why we use functions/methods in the first place. There are several reasons but one of the important ones is to let humans reading the code read the program at a higher level without getting bogged down in the low level details.

      With functions the programmer can choose arbitary names for ordinary methods. Decent programmers choose ones that at least somewhat reflect what the function does and try not to use the same name for two different things. So the person reading the code just has to remember what each function does.

      With operator overloading (at least the forms of it I have seen) you can't create your own operators, you can only redefine existing ones. So when coders find something that it would be nice to make an operator (because it makes a common operation more concise) but doesn't have a standard operator they tend to reuse (many would say abuse) a standard operator. That in turn means that operator now has two very different meanings in the same code depending on the types involved. This in turn means that every time I want to know whether a statement is performing a shift or writing something to a stream I have to check up on the types of the variables involved.

      Besides, GCC makes quite heave use of GMP which is the *IDEAL* candidate for operator overloading.
      Agreed, that is the sort of place where operator overloading definately should be used.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    11. Re:Safe subset by turgid · · Score: 1

      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.

      The very fact that they need to consider defining and enforcing an arbitrary subset of the language should tell you all you need to know.

      It'll all end in tears, mark my words.

    12. Re:Safe subset by Anonymous Coward · · Score: 0

      What is the difference between these two examples?

      function example:

      z = add(x, y);

      overloaded operator example:

      z = x + y;

      In the first one, it is clear that a function is being called. The function could contain a bug (I consider a function named "add()" that subtracts instead to be very buggy indeed).

      For the second one, you can't just look at it and see what is going on. You need to know the type of x, the type of y, and then you need to look at the class methods to see which overload function will be called.

      In the debugger, this is easy; you just "step in" on this line and see where you end up. But it's absolutely true that more is hidden with operator overloading.

    13. Re:Safe subset by tp_xyzzy · · Score: 1

      Here's potential problems Gcc folks will encounter when they start to implement this nice plan:
        1) Defining the rules will be difficult
        2) Enforcing the subset of C++ is impossible
        3) Every C++ developer will think _all_ of C++ is ok since they allow _some_ C++ code.
        4) Next day they receive 10000 patches which all break the rules
        5) They do not have enough resources to reject all "improvements"
        6) They will have a flame war about the rules and whether sibling calls and dreaded diamond inheritance should be allowed
        7) Their use of STL creates problems with compile times
        8) Many developers leave because they don't want to wait for compiles (compared to just writing code)
        9) A central header file will #include vector, map and iostream just so that they do not need to #include them everywhere, making compile times even worse
      10) The new features that are actually approved to be used are misused
      11) Use of classes and pointers will create a dependency mess
      12) Their final approved C++ feature list will look like this:
            a) classes
            b) single inheritance
            c) constructors/destructors
            d) reference parameters
            e) forward declarations
            f) pure virtual functions
      13) Passing this-pointers through C code callbacks will be problematic
      14) The project will be declared failure, C++ blamed
      15) Linus becomes a C++ programmer

    14. Re:Safe subset by Anonymous Coward · · Score: 0

      Name mangling of classes and namespaces is pretty straight forward. Every half decent C library has some naming scheme like [library]_[module]_[function]. Not that much different from [namespace1]_[namespace2]_[function] or [namespace1]_[class1]_[function].

      IMHO two features make name mangling in C++ difficult: templates and function overloading.

    15. Re:Safe subset by Spacelem · · Score: 1

      As far as I know Linus isn't part of GCC, but he has clearly stated that he does not want C++ in the Linux kernel.

    16. Re:Safe subset by GooberToo · · Score: 1

      Not to mention, not only are there fewer lines but initialization can't be forgotten.

      Thusly, but doing this:
      MyClass m(foo, bar);

      This is not only required, but can't be forgotten. Which, unsurprisingly, is a common source of errors among coders.
      MyClassInitialize(&m, foo, bar);

      Which means not only are you doing more with less code, but you also avoid a common problem of simply being human.

  22. 80's technology by toolslive · · Score: 0, Flamebait

    C++ is 80's technology, and as such filled ugliness that was considered sexy at the time. Just like 80s pubic hairdressing it's just too much to see the essence. Try to compare Haskell's polymorphism to C++ templates and you will get the picture. Anyway, to you really think 30 years of computer science since C++ could not come up with anything better? Why not take advantage of the fact that you are very late in taking up a new technology and skip a few decades?

    1. 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.
    2. Re:80's technology by Zo0ok · · Score: 1

      Someone moderated you Insightful. Makes me wonder...

      And about modern technology...
      Maybe rewriting GCC in python, and rewriting python in Assembler?

    3. Re:80's technology by roman_mir · · Score: 1

      and DOM, don't forget the DOM.

    4. Re:80's technology by Prof.Phreak · · Score: 1

      Not a python fan myself, but what would be the downside of rewriting gcc in python?.

      via cross-compilation, you can still make a binary for any platform you like---and it's probably much easier to work with and maintain than a ton of C/C++ code.

      --

      "If anything can go wrong, it will." - Murphy

    5. Re:80's technology by Anonymous Coward · · Score: 0

      No types.

    6. Re:80's technology by delphi125 · · Score: 1

      and DOM, don't forget the DOM.

      I've been trying to for years and then you mentioned it, you insensitive clod

    7. Re:80's technology by Zan+Lynx · · Score: 1

      It would also use even more gigabytes of RAM and run like a snail.

      Python is nice to write but runs worse than Java.

    8. Re:80's technology by iggymanz · · Score: 1

      it would be slower than fuck, but would certainly provide mental masturbation for the ivory tower types. The ivory tower types don't have engineering pragmatism but they sure make pretty code sculptures

  23. 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 Joce640k · · Score: 1

      Using STL frees you from having to do manual memory management. I imagine compilers do a far bit of string manipulation and put things in dynamically-sized buffers, all of which are prone to leaks, overflows and all the other evils of C.

      --
      No sig today...
    6. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 1, Interesting

      Why, exactly, is using STL a greater good from a compiler side?

      Same as for any other large programming project: It makes it easier to write and maintain.

    7. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      My guess is that the programmers who prefer C++ before C don't have a clue about what the compiler actually has to do with all that C++ code.

    8. Re:Maybe they've grown up a bit by Eponymous+Coward · · Score: 1

      I thought of a second good example: smart pointers.

      Something like Boost's scoped_ptr is simple, as fast as, and no more memory hungry than a built-in pointer.

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

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

    11. Re:Maybe they've grown up a bit by siride · · Score: 1

      I'm sure the folks who work on GCC do and yet they still made this decision. That should tell you something.

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

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

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

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

    16. Re:Maybe they've grown up a bit by 0xABADC0DA · · Score: 1

      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.

      Not quite. The C++ version can only have the comparison function inlined if a separate version of qsort is generated, which means some form of source code must be available to it. But this is also possible in C if the compiler has seen the qsort code. If you #include "qsort.c" instead of linking to it in libc.a then the C compiler can see that the function pointer is not modified and emit a specialized version of qsort optimized just like the C++ one.

      C++ forces the compiler to not use a ".o is everything" model, but to in effect recompile parts of other modules over and over again. It's the forced complexity of compilation that really is giving C++ binaries better performance, not anything defect in C itself, because it gives the compiler access to more of the source code.

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

    18. Re:Maybe they've grown up a bit by Joce640k · · Score: 1

      | "performance can be 4x SLOWER with the stl than by using c99"

      I'd like to see you back that claim up with real code...

      --
      No sig today...
    19. Re:Maybe they've grown up a bit by Joce640k · · Score: 1

      | "object-oriented programming is a paradigm, not a language feature"

      True enough, but language features can make it MUCH easier to use.

      | "You can even do OOP in assembler "

      True again, but if I decide to make a function virtual in C++ I just type "virtual" and let the compiler figure it out. In assembler I have to go through and find all the references the the function and change them to do double-indirection. The assembler isn't going to help me by printing any warnings about the ones I missed, and they're going to bomb.

      --
      No sig today...
    20. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      The stl has overhead, plain and simple. I've tested it and seen the difference. Have you? It's why the first thing I do with stl code is replace it.

    21. Re:Maybe they've grown up a bit by shutdown+-p+now · · Score: 1

      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.

      What it gains is readability. When 10 lines of C code doing manual error checking and memory cleanup are replaced by a single line of C++ code that does the exact same things implicitly - and when this substitution is repeated over and over again across the entire code base - the result is that higher-level things - what is being done - are highlighted more over mundane housekeeping that is so common in C code (particularly well-written one, which always checks error codes and does cleanup as needed).

      Given that gcc is often blamed for being hard to understand from implementation perspective, it may be a very good thing. Readable code is maintainable code. Maintainable code is code with less bugs. Furthermore, more readable code means more projects that build on gcc rather than reinventing the wheel.

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

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

    24. Re:Maybe they've grown up a bit by shutdown+-p+now · · Score: 1

      Not quite. The C++ version can only have the comparison function inlined if a separate version of qsort is generated, which means some form of source code must be available to it. But this is also possible in C if the compiler has seen the qsort code. If you #include "qsort.c" instead of linking to it in libc.a then the C compiler can see that the function pointer is not modified and emit a specialized version of qsort optimized just like the C++ one.

      This is true, but ANSI C standard does not include "qsort.c". It only includes "stdlib.h", which provides only the declaration for qsort. Unless the compiler special-cases it, or is able to inline this kind of thing across object files, this does mean that the standard C qsort() is slower than standard C++ std::sort().

      There's one other thing. The way qsort and bsearch are defined, the comparator/predicate have to access elements indirectly via untyped void* pointers. Though a smart optimizer can still understand this and remove the indirection while inlining (just checked with VC++, and it did so; no doubt, gcc can do so as well).

    25. Re:Maybe they've grown up a bit by ultranova · · Score: 1

      Using STL frees you from having to do manual memory management.

      So do Java, Python, Lisp, or pretty much every non-C programming language in use nowadays. This is not a feature worth mentioning nowadays, any more than protected memory in modern processors.

      --

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

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

    27. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 1, Insightful

      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.

      This myth has been repeated to death thousands of times over the years, and disproven on nearly every occasion. Every micro-optimization C++ newbie thinks they can prove that the C++ STL results in slow code. Ultimately, the cause for his results are of writing inoptimal code.

      But it seems you didn't even get that far. From what I gather from your post, I'd guess the last time you used C++ to be sometime near the year 2000. Maybe you should check again; C++ compilers have advanced much since then in many respects.

      As the STL is good enough for many game developers, I heavily doubt you have the experience to prove it is actually slower. You can read about EA's inconclusive experiments in their EASTL paper. EA's replacement STL provides more efficient container allocators -- allocator replacement is a feature of the STL and something all C++ programmers do at one point -- and mainly optimizes the STL for console C++ compiler deficiences (usually poor templating support).

      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.

      No one cares about OOP in C++ anymore. C++ truly has no advantages for it. C++'s unmatched advantages (except for in D) are in compile-time metaprogramming, or generic programming. As you are citing the STL, you should understand this. If the STL were written in terms of runtime polymorphism, it would be much slower due to no longer generating C-optimal code.

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

    29. Re:Maybe they've grown up a bit by SnarfQuest · · Score: 1

      But gcc has good algorithms and containers! There's a nice set for each front end, another set for the middle with some additional nice ones in the optimization code, and several more in each back end. Why would you want to lose any one of these for some STL code?

      --
      Who would win this election: Andrew Weiner vs Andrew Weiner's weiner.
    30. Re:Maybe they've grown up a bit by 0xABADC0DA · · Score: 1

      Unless the compiler special-cases it, or is able to inline this kind of thing across object files, this does mean that the standard C qsort() is slower than standard C++ std::sort().

      So you compile libc with -flto and it puts the parse tree into the object file. Problem solved, and by including "some form of source code" like I said. Try even getting 'export' to work in C++, let alone this.

      I don't know if -flto is currently embedding enough to actually generate a specific version of qsort, but it certainly could.

      There's one other thing. The way qsort and bsearch are defined, the comparator/predicate have to access elements indirectly via untyped void* pointers. Though a smart optimizer can still understand this and remove the indirection while inlining

      A smart optimizer is a given for anything to do with fast code, whether in C++ or C or any other language. And C compilers are pretty much past masters at knowing the type a void* really points to.

      I'm not sure what you are trying to say here. That C++ code is easier for the compiler to optimize?

    31. Re:Maybe they've grown up a bit by EQ · · Score: 1

      Is STL still not thread safe? That's been a bit of an issue. Using STL for systems programming is generally a stupid thing to do.

      --
      Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo! http://goo.gl/J9bkO
    32. 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.

    33. Re:Maybe they've grown up a bit by sustik · · Score: 1

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

      Seconded. Also: // looks nicer for comments than /* */

      Regarding performance: recently I was asked to help with a memory bloat problem. On AIX the code was using more memory than on Linux. A new replacement was used to track all allocations and we found that the AIX STL implementation uses more memory. Not much one can do about it.

      One more thing: delete() and free() should return the size of the freed area. The lack of that I consider the most unfortunate language design decision. Why could they not fix this with C++? This prevents effective memory use monitoring.

    34. Re:Maybe they've grown up a bit by Suiggy · · Score: 1

      It's not hard to surpass the performance of most STL solutions. See EASTL, EA's version of STL written specifically for games requiring high performance. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html And as another simple example, the associative hashtable container in TR1/C++0x standard libraries (unordered_map) uses chaining for resolving hash-table conflicts, but you could write an alternative that uses open addressing that would be faster in numerous occasions where you don't need to preserve iterator validity across hash table resizing, and the key/value object size is relatively small (no more than a few machine words each). That said, STL overall is pretty decent, it usually has better performance than a lot of this stuff I've seen people do in C. Many C coders use hand written linked lists instead of using a data structure more suited to the task at hand, such as a balanced search tree or hash table when needing to perform a lot of searches across a data set.

    35. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      My java program is replacing a C one. Its more than 5x faster and does more (so it *should* be slower since its doing more flops).

      The problem with doing it yourself is that as a java programmer I can write fast java. But that doesn't mean i can write fast C. Also you don't do things the same anyway. STL vers C is the same. Your STL code is 4x slower. Thats not the same as STL is 4x slower than C.

    36. Re:Maybe they've grown up a bit by Suiggy · · Score: 1
      You wouldn't want to make the STL containers thread-safe by default, that would add an unnecessary degree of overhead to the generated code. It would be like making a C compiler make all C-style arrays thread-safe. Doing that would be plain stupid.

      That said, the C++ standard library is getting threading facilities added to it in C++0x. Just the basics though. Atomics, threads, mutexes, conditions, and futures. But this isn't stuff you can't currently do by rolling your own code using the operating system's APIs. The C++0x threading libraries just act as a thin abstraction layer over this.

      As for more advanced threading libraries, check out Intel's Threading Building Blocks or Microsoft's Parallel Patterns Library. Parallel algorithms and transformations (for-each, generate, map, reduce, etc.), task-based thread pooling and dependency graphs, different types of synchronization primitives, lockfree concurrent queues, lists, associative maps and sets, and a bunch of other useful things for high performance threading. I wouldn't be surprised if some of this stuff eventually makes it's way into Boost and the C++ standard library itself.

      There's also talk of adding in software transactional memory primitives to both Intel TBB and MS's PPL now that a number of the more difficult problems have been ironed out by the academic community.

    37. Re:Maybe they've grown up a bit by Homburg · · Score: 1

      GCC uses garbage collection, so it's not doing manual memory management anyway. In general, automated memory management is an advantage of C++ over C, but it might not be one that matters much for GCC.

    38. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      RAII, smart pointers, and scope guards all contribute towards making manual resource tracking a problem of the past in C++. Raw pointer newing in general should get you fired in most workplaces today.

      malloc and free should never be used in C++ code. It won't construct the object, and an overloaded new/delete will not be called. If for some reason you desire non-constructed object allocation, you should prefer ::operator new(size_t) and ::operator delete (not to be confused with new and delete operators).

    39. Re:Maybe they've grown up a bit by Homburg · · Score: 1

      Why are you using malloc and free in a C++ program? You should a) be avoiding direct use of dynamic allocation whenever possible, which the STL containers allow you to do and b) using new and std::auto_ptr in classes that wrap any application-specific dynamic allocation you do need, thereby automating deallocation on destruction.

    40. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      jeez why don't they just use a modern language other than C?

      Such as Ocaml or Haskell?

      Why is anything high level done in C at all?

    41. Re:Maybe they've grown up a bit by Darinbob · · Score: 1

      But STL tends to bloat code severely. It is great in that it has some nice algorithms in it, but you can do those exact algorithms in C. The drawback is that they're based on templates and are not object-oriented. Current compiler technology is awful in this regard, and the tend to duplicate code like smart-macros when templates are instantiated. OO reuses object code, templates reuse source code. Not a problem if you're on a big beefy machine with a ton of memory and ample caching (your typical desktop) but it's a serious drawback if you're on a small machine with limited resources. The lack of OO with STL is a hindrance in itself; compare to the elegance of container classes in Smalltalk for instance.

      With novice programmers STL has the added drawback in that it's used as an all purpose tool; ie you've got a hammer and everything looks like a nail. People so wary of implementing a tiny data structure that they end up using STL maps inappropriately. I've seen this. Maps used where the there are a tiny number enumerated keys where an array with 10 elements would have sufficed. I also see plenty of novices (actually programmers with years of real world experience) not understanding the side effects behind STL; who fail to take into account all the copy constructor overhead, or the performance hit from inserting and deleting from vectors.

      Not necessarily crappy programmers, but they've been taught over time to look at the big picture and use a programming language as duct tape to tie together pre-existing libraries, and they never learned to understand the performance issues of what they're doing.

    42. Re:Maybe they've grown up a bit by Darinbob · · Score: 1

      But using the STL sort with these compares inline means that the sort routine is essentially recompiled from scratch, instead of being from a library. If you are sorting an array of integers, and an array of strings, and an array of pointers, then you've got 3 copies of the sort recompiled and linked in. With qsort in the C library you've got just a single sort, plus 3 compare functions.

      Ok, if you've got lots of memory, then maybe STL isn't a drawback. But at second glance you've also got the problem that if you're doing these 3 sorts close to each other that your locality of reference is messed up possibly. Instead of one sort function plus three tiny compares in cache, you've got three full sort functions. Now take that problem and add in similar effects to all the STL containers in your app and your cache performance takes a big hit, and probably some paging performance hits too. So you take the PC programmer solution and assume you've always got the latest generation CPU with multi-level caches. It's sort of wasteful, like buying a bigger car because your kids are getting too fat.

    43. Re:Maybe they've grown up a bit by arth1 · · Score: 1

      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.

      The scope of the damage differs, and is a heck of a lot easier to debug for others without STL.

      Yes, a crappy shot is a crappy shot no matter what, but I'd rather see a crappy shot wielding a rifle than a submachine gun.

    44. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      I disagree.

      A crappy programmer using the STL in C++ often results in a functioning but extremely slow program with perhaps a few vulnerabilities.

      A crappy programmer in C often results in a half-functioning but extremely buggy and insecure program littered with dozens of vulnerabilities.

      A good programmer in either will suffer none of these issues. So I don't see the point in discussing it.

      It's true that C++ takes (much) longer to learn. But I don't choose languages based on their beginner friendliness value. C++ is intuitive enough once you get past the preliminary stages. And someone skilled in another higher level language, usually finds it easy to adapt to C++. It's those coming from a C background and who are overwhelmed, or those who are simply just bad programmers, who find it a major obstacle.

    45. Re:Maybe they've grown up a bit by arth1 · · Score: 1

      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.

      If you need to inline a sort, you're probably doing something wrong in the first place.

      And if you really need to do it that way anyhow (instead of, say, a Schwartzian transform to get a much smaller dataset sorted), you probably also should choose a sort algorithm that reflects your data, instead of grabbing the qsort hammer from the toolbox.

    46. Re:Maybe they've grown up a bit by Joce640k · · Score: 1

      LOL!

      Is all I can say to that. I was programming z80s and 6502s in hexadecimal before all you whippersnappers were born.

      When I started writing C++ I was as suspicious as anybody but after a few months of looking at disassembly of the code produced from STL functions I managed to get over it.

      Clue: The people who make C++ compilers aren't stupid. They actually look at, and care about, the code produced by their compiler.

      --
      No sig today...
    47. Re:Maybe they've grown up a bit by LordVader717 · · Score: 1

      That's only true if you assume that they would otherwise know nothing about the libraries and always write their own implementations optimally.

      But in reality it's perfectly possible to use the libraries and still understand the workings. GCC shouldn't be trying to educate it's programmers.

    48. Re:Maybe they've grown up a bit by maxwell+demon · · Score: 1

      jeez why don't they just use a modern language other than C?

      Because they don't desire to completely rewrite their large code base?
      The nice thing about C++ is that you don't have to rewrite all your C code to be able to use C++ features. You can introduce C++ features gradually.

      Now you may argue that the code would almost certainly get better in a complete rewrite. But until that rewrite is finished, the compiler may have gotten irrelevant due to lack of development.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    49. Re:Maybe they've grown up a bit by maxwell+demon · · Score: 1

      malloc and free should never be used in C++ code.

      Never say never.

      If you have to interface with C code, and you have to allocate memory which will be deallocated in the C code, or deallocate memory which has been allocated in the C code (the latter is actually more common), you have to use malloc/free, because that's what the C code uses. It's an error to use delete on memory allocated with malloc, or free on memory allocated with new.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    50. 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.

    51. Re:Maybe they've grown up a bit by HuguesT · · Score: 1

      Precisely, non-C !

      Here they are talking about finally using something else *than C* to continue development of GCC.

    52. Re:Maybe they've grown up a bit by Frnknstn · · Score: 1

      You misread his response. He says:

      Using STL frees you from having to do manual memory management

      and you start prattling on about vanilla C++.

      Step by step:
      If you are using STL, chances are you are using STL containers to hold a large portion of your data.
      If an STL container is holding your data, you don't have to worry about managing that memory.
      Thus, STL frees you from having to do manual memory management.

      There will, of course, be cases when you do want to manually allocate a block for yourself. That's what new() is for. What on earth would a C++ user want to use your 'malloc' for? Why are you giving amateur-level C++ advice(Remember kids, always release your blocks when you are done using using them!)? Is is because amateur-level is the limit of your C++ knowledge?

      I hope I am not coming across too aggressively here, but I see you up and down this thread, giving C++ advice with very little to support it. For example, where are these STL vs. C benchmarks you claim to have done?

      --
      If it's in you sig, it's in your post.
    53. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      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.

      ... and having that ability that adds checking overhead on EVERY access. Want to try again?

    54. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      2 years ago, when I argued that we should remove it because it was still a performance hit. Proved it, removed it, converted the code to standard c99, not c++.

      Much faster.

    55. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      There are plenty of times when the stl simply isn't needed. People will drag the whole thing in because they want to parse out an initialization file. How dumb can you get? If you can't write a simple ini file parser yourself, you should go back to school. This is one of those things that can be done in a few lines of c, never mind c++.

    56. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      smart pointers, weak pointers, etc., bring their own problems. Just keep track of it in the first place. Design for it. Account for it. Test for it. You're going to need to anyway, so why not keep the code simple ...

    57. Re:Maybe they've grown up a bit by tomhudson · · Score: 1
      Because I can keep track of my memory allocations and frees. I learned long ago, the hard way, to make sure my mallocs match up with my frees, and to make sure I knew who "owns" what.

      And sometimes I just like the idea of being able to take a nice chunk of ram, and sometimes look at it as a series of raw bytes, and sometimes as an array, and sometimes as something else. Back when I was writing assembler, everything was just memory anyways :-)

      In comparison, std::aut_ptr sucks. For me. YMMV, and you're welcome to your opinion. I'm just saying the "textus receptus" that the STL is the greatest thing since sliced bread, has resulted in the dumbing down of a certain species of programmers, who can use the stl but are lost without it.

    58. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      Yes, usually this can be designed around... by not using the heap at all.

      shared_ptr alleviates a problem not often felt in the C world, a one-to-many pointer relation, and cannot reasonably be compared to new/delete. Managing shared raw pointers across hundreds of translation units is not typically something that can easily be designed around. But deque<shared_ptr<...>> does it with hardly any thought required (occasionally to later detriment, I admit).

      unique_ptr and auto_ptr (now deprecated) are the real comparison to new/delete. And when you value code noise minimization, they are very convenient.

      Manual memory tracking in C++ isn't as simple as you suggest, due mainly to exceptions. If you allocate Object1 and Object2, and either new or the constructor throws an exception at Object2, you're screwed. But unique_ptr<Object2>(new Object2) solves this through automatic use of RAII.

    59. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      No type should be freed or deleted across shared library/executable boundaries, without making certain guarantees. If the deleter has a differing C/C++ CRT version, it will attempt to deallocate from the wrong heap/free store and explode. This is an issue if

      • either Recipient or Passer are linked to static CRT
      • Recipient or Passer are linked to mixed Debug and Release shared CRT
      • Recipient or Passer are linked to mixed Multithreaded or SP shared CRT

      It's basically playing russian roulette. Eventually, you will fail and succumb to this event.

      In most cases this is solved by providing exported factory classes (for C++) or functions (for C) that manage construction and destruction for user types. For SC++L containers, abandoning the STL allocator is also required.

      Alternatively, for C++, you can overload operator new and operator delete for a particular class. Using new or delete from elsewhere will automatically call the appropriate class-overloaded operator new/delete, even across boundaries.

      Furthermore, non-POD types have more stringent guarantees for passing. If the recipient has a differing version of a non-backwards- or non-forwards-compatible static library/implementation -- such as any Standard C++ Library headers -- the object structure can change at whim. Passing a std::string to a shared library or executable that was compiled by another compiler (or even compiler version) can have bad consequences.

    60. Re:Maybe they've grown up a bit by thenextstevejobs · · Score: 1

      What's the difference, for the sake of your argument, between using the STL and using existing C libraries for data structures instead of creating your own? glib anyone?

      --
      Long live the BSD license
    61. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      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.

      So what you mean is that you had something like

      char* array = malloc(1 * sizeof(char));
      *(array + 0); // success
      *(array + 1); // error
      array = realloc(array, 2 * sizeof(char));
      *(array + 1); // success

      In other words, the same thing as

      std::vector<char> vec(1);
      char* array = &vec[0];
      *(array + 0); // success
      *(array + 1); // error
      vec.resize(2);
      array = &vec.front();
      *(array + 1); // success

      Which compiles down to nearly the same very instructions.

      or more simply...

      std::vector<char> vec(1);
      vec[0]; // success
      vec[1]; // error (assert at debug)
      vec.resize(2);
      vec[1]; // success

      operator[] calls will be optimized away.

      Welcome to 1998.

    62. Re:Maybe they've grown up a bit by smellotron · · Score: 1

      In many cases, use of STL results in near optimal code.

      Whoa whoa whoa there! What STL author ever said that? It's probably hard/impossible to beat <algorithm>; but on the container side, all you can say that using the STL is better than writing your own generic containers. There are plenty of reasons why a specialized container can do better. Let's see...

      • The requirement that custom allocators all share from a global memory pool prevents certain optimizations, such as a node-based container owning its own memory directly to avoid reallocation. Even boost's fastest allocators come with comments to the effect that some of their behavior is hampered by the std::allocator API.
      • vector is nearly as good as an array - but it is forced to be dynamically allocated. A custom stack-based allocator would be nice for avoiding that allocation, but that breaks std::vector::swap() and possibly other parts of the interface.
      • anyone who doesn't need bidirectional iteration can cut their memory overhead in half by using a singly-linked list instead of std::list.
      • There is no middle-ground between std::map and std::unordered_map. Computer Scientists have been inventing specialized tree and hash data structure for decades, because one size does not fit all.
      • Many cache-aware data structures may want to size or align themselves to cache boundaries, but popular implementations of the STL do not do this. One trivial example is a stack that uses local memory if the contents fit within a single cache-line, but jumps out to a dynamically-sized array beyond that size.
      • Not all associative or otherwise-sorted structures are comparison-based. Radix/bucket sorting and tries come to mind.

      Don't get me wrong—I love the STL. But I love it because it is generic, not because it is optimal.

    63. Re:Maybe they've grown up a bit by PeterHammer · · Score: 1

      Why, exactly, is using STL a greater good from a compiler side?

      Same as for any other large programming project: It makes it easier to write and maintain.

      How, exactly, is easier to write and maintain code a greater good from a compiler side?

    64. Re:Maybe they've grown up a bit by PeterHammer · · Score: 1

      I love it. A good ole lets duke it out between C and C++ programmers. Such a gentleman's sport compared to the (more full of opinionated ignoramii) java vs python vs ruby vs perl debates - or even worse - the dreaded apple fanboy vs linux geek vs windows pro debates that have become the predominant news on slashdot these days.

    65. Re:Maybe they've grown up a bit by Pseudonym · · Score: 1

      No, they simply memorize magical mantras that, when regurgitated, will do what they want.

      I believe the term you're looking for is "cargo cult programming".

      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.

      Quite. Indeed, getting back to the topic at hand, people seem to have forgotten (or perhaps never realised) that GCC already uses garbage collection. Arguably, GCC hasn't been written in C for a while now.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    66. Re:Maybe they've grown up a bit by Pseudonym · · Score: 1

      But anyway, normally you wouldn't use them, because such a combination is essentially the same as an overly complicated std::set.

      It's only complicated because writing conforming STL containers requires you to understand bits of the STL that most users don't need to understand. But it's not overly complicated at all. On the contrary, it's a perfectly respectable data structure which satisfies mostly the same concepts as std::set (the iterator invalidation rules are different), only with a very different (memory and time) performance profile. If that's the performance profile you need, that's what you should use.

      It's something of a C++ rite of passage to implement a Simple Associative Container interface on top of std::vector. As a disclaimer, though, Associative Container has complexity guarantees which sorted vectors don't support, which is why they're not in Boost.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    67. Re:Maybe they've grown up a bit by exomondo · · Score: 1

      A good programmer in either will suffer none of these issues. So I don't see the point in discussing it.

      And he/she will be more efficient as he/she isn't re-inventing the wheel each time.

    68. Re:Maybe they've grown up a bit by Pseudonym · · Score: 1

      No one cares about OOP in C++ anymore.

      That's only half true. Nobody cares about OOP in the Alan Kay sense; if we really need that, we use futures, iterators, threads, MPI or whatever is most appropriate.

      But objects in C++ are ubiquitous because they are its module system, and it's a module system that gives you modules that are instantiable and inheritable. C99, by contrast, doesn't have a module system.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    69. Re:Maybe they've grown up a bit by Pseudonym · · Score: 1

      First off, as previously noted, STL algorithms are designed so that they inline aggressively. When you call g_list_sort_with_data, it calls your GCompareDataFunc every time it needs a comparison. But when you call std::sort, it inlines that comparison function. If the comparison function is a couple of instructions, you save big on function call overhead.

      Similarly, data structures are also inlined. A GList is, physically, a list of pointers to payload data. An STL list, however, is a list of physical data. So if your GList stores doubles, you waste memory (a pointer per list cell plus probably extra malloc overhead to store each item), and time spent pointer chasing.

      Secondly, the STL is far more type-safe than glib. You (mostly) can't accidentally store a struct in a list of integers.

      Thirdly, glib is verbose compared to the STL. Compare g_array_index(a, i) with a[i]. Yes, using a decent editor with name completion doesn't make it necessarily any harder to write, but that's not the point.

      Finally, the STL is exception safe and, if your OS allows it, thread cancellation safe. But, of course, C doesn't have exceptions. It has return codes that everyone forgets to check.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    70. Re:Maybe they've grown up a bit by exomondo · · Score: 1

      2 years ago, when I argued that we should remove it because it was still a performance hit. Proved it, removed it, converted the code to standard c99, not c++.

      Much faster.

      What was your example that was 4x slower?

    71. Re:Maybe they've grown up a bit by Pseudonym · · Score: 1

      GCC uses garbage collection, so it's not doing manual memory management anyway.

      That's not true. GCC is using manual memory management for some data structures and GC for others. This makes sense considering the design requirements for GCC. Most data structures in a compiler don't have complex memory lifetimes. For example, the data object associated with a procedure/function is created when it's parsed and never really "goes away" after that, so there's no advantage for using automated memory management for them.

      However, code transformation passes tend to manipulate lots of small objects with difficult to follow patterns of sharing. Sprinkling code which is meant to be doing optimisation with stuff to keep track of which objects are garbage would cause extreme bloat and make maintaining the code ten times harder than it needs to be. GC is a clear win there.

      Remember, GCC used to use the Boehm collector, but the developers found managing everything with it to be too heavy-weight for their purposes. The community is extremely fortunate that the developers of one our most mission-critical pieces of software have sound judgement and good taste.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    72. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      It's called not reinventing the wheel. Using an INI library would be ideal, a generic solution more ideal. And in fact, one exists.

      namespace pt = boost::property_tree;
      pt::ptree ini;
      pt::ini_parser::read_ini("/some/ini/file.ini", ini);
      std::string text = ini.get<std::string>("section.value");

      Why use a library, when writing an INI parser takes 10 minutes? Because a solution like the above is more consistent, readable, portable, generic, likely more performant, standardized, is guaranteed more safe, supports features like type-safety & streams & exceptions & iterators & algorithms & locales, and much more flexible. How long would it take to write an equivalent library in hours of spare time? Months.

      As an added benefit, if I desired to, I could now serialize this resultant in-memory data structure to binary or XML format with little additional effort. Isn't that nice?

      It even works with things like std::merge, std::find_if, and std::unique. And it all comes in one very lightweight header-based library. And the best part is, it has negligable overhead, and unused components are not compiled -- benefit of the raw power of metaprogramming.

      Did you know, I once caused a buffer overflow in Knights of the old Republic (PC game) by writing exceedingly long lines in one of its INI files? This bug was likely shared by all previous Bioware Aurora games, including Neverwinter Nights. This is the main reason why you should avoid custom half-baked implementations whenever possible.

    73. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      The problem with C++ is that the STL is based on templates, which do not mix well with inheritance. If you have a subclass B of A then you can't put objects B into a container of A. You can use a container of pointers, but STL's main benefit is that it owns the objects themselves and does the memory management for you.

      You can make a container of Boost's shared_ptr, shared_ptr will do your memory management, but the extra layer of functionality is undermining the efficiency proposition. Also, shared_ptr B> is a distinct type from shared_ptr. Even though there are cast operators, this still gets in your way.

      Furthermore, and regardless of the above, there's no language-supported commonality between the containers themselves. So, for example, even though list and vector both have push_back(), there's no interface class, so you can't have a pointer to a push_back()able container.
      Similarly, you can't extract a common interface to say list and list B*> even though push_back(&b) ought to work for both.

      Now, STL is really about implementations of algorithms, whereas inheritance is about interfaces between program components. So why not wrap STL containers with things that do possess base classes and can handle disparate element types? Well, it's hard to do this. Harder if you want it to still be fast and not just throw all type-safety in the bin using hacks. Iterators, for example, are really awkward to polymorphise.

      The interesting thing is that the "ideal" C++ implementation of a semantic tree data structure as found in compilers would want to use both STL and inheritance: the STL would allow inherently ordered and unordered multiplicities to be represented efficiently while hiding the container algorithms (important if a program has 5000 top-level functions, for example). Inheritance would allow the tree to embody the classifications found in programs: for example literals are kinds of expressions, expressions are kinds of statements and so on.

      It looks painfully apparent that C++0x will not address this "elephant in the room" and is instead content to faff around with syntactical sugar and "small picture" optimisations.

    74. Re:Maybe they've grown up a bit by shutdown+-p+now · · Score: 1

      You can make a container of Boost's shared_ptr, shared_ptr will do your memory management, but the extra layer of functionality is undermining the efficiency proposition. Also, shared_ptr B> is a distinct type from shared_ptr. Even though there are cast operators, this still gets in your way.

      That's why Boost has ptr_vector, ptr_list etc - which own the pointers they contain.

      And in C++0x, you just use std::vector<std::unique_ptr<T>> - it does not have any overhead over a raw pointer (due to move constructors), but will ensure correct ownership transfer & maintenance.

      Furthermore, and regardless of the above, there's no language-supported commonality between the containers themselves. So, for example, even though list and vector both have push_back(), there's no interface class, so you can't have a pointer to a push_back()able container.
      Similarly, you can't extract a common interface to say list and list B*> even though push_back(&b) ought to work for both.

      You can, it just requires some hackery. But the basic principle is the same as what std::function does to wrap an arbitrary function object in the same type - define a single abstract class, and a derived class template which is instantiated for every distinct type, and maps its members (such as push_back etc) to virtual methods on itself.

      That said, the fact that - unlike std::function - there is no existing implementation for such a thing, shows that it is not particularly useful. Indeed, the main reason why you'd want it is for generic algorithms and other generic handling of containers; but you can do it much more efficiently with templates, and in C++, that is indeed the idiomatic way of handling that.

    75. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      The problem with C++ is that the STL is based on templates, which do not mix well with inheritance. If you have a subclass B of A then you can't put objects B into a container of A. ...

      This isn't a "problem" of the STL, this is a "problem" with language facilities. A container cannot accept types A and B by value without slicing B. The two ways to do this are, you guessed it... [abstracted] dynamic allocation, and templates.

      If you want something different, try
      vector<boost::variant<A,B>> container;

      or
      vector<boost::any> container;

      or
      boost::fusion::vector<A, B> container(A(), B());

      In fact, variant and fusion are probably the best methods here, because they let you easily apply the visitor pattern.
      class A
      {
      public:
      operator std::string () const { return "A"; }
      };

      class B
      {
      public:
      operator std::string () const { return "B"; }
      };

      struct visit {
      typedef void result_type;
      template<typename T>
      void operator () (T const& obj) {
      std::cout << boost::implicit_cast<std::string>(obj) << std::endl;
      }
      };

      With variant
      vector<boost::variant<A,B>> container{A(), B()};
      visit visitor;
      std::for_each(container.begin(), container.end(), boost::apply_visitor(visitor));

      or with fusion/mpl
      boost::fusion::vector<A, B> container(A(), B());
      boost::fusion::for_each(container, visit());

      You can use a container of pointers, but STL's main benefit is that it owns the objects themselves and does the memory management for you.

      You can make a container of Boost's shared_ptr, shared_ptr will do your memory management, but the extra layer of functionality is undermining the efficiency proposition.

      It sounds like you are lamenting having to get a little dirty. Polymorphism is dirty in C++, so this a natural response.

      I think you are grossly overestimating overhead of shared_ptr. If it's a bottleneck, then fix it. And as shutdown -p implied, shared_ptr was not meant for this purpose. unique_ptr was, and auto_ptr should have been (but was fundamentally broken). shared_ptr is overkill when you don't need to pass its ownership around. It's called shared pointer for a reason.

      Also, shared_ptr<B> is a distinct type from shared_ptr<A>. Even though there are cast operators, this still gets in your way.

      Uh, no? You do this in the same way you do any runtime polymorphism.
      A* ptr1 = new A;
      A* ptr2 = new B;

      Same as...
      vector<shared_ptr<A>> container;
      container.push_back(new A);
      container.push_back(new B);

      You can even get crazy and pass in a custom deleter function per shared_ptr.

      Furthermore, a

    76. Re:Maybe they've grown up a bit by PastaLover · · Score: 1

      The stl has overhead, plain and simple. I've tested it and seen the difference. Have you? It's why the first thing I do with stl code is replace it.

      Why the hell would you replace STL code except for absolutely performance critical sections (and even then... 4x? pocket change).

    77. Re:Maybe they've grown up a bit by tomhudson · · Score: 1

      4x is not pocket change when you're dealing with thousands of transactions a second.

    78. Re:Maybe they've grown up a bit by Anonymous Coward · · Score: 0

      LOL Windows fag

    79. Re:Maybe they've grown up a bit by David+Greene · · Score: 1

      Furthermore, and regardless of the above, there's no language-supported commonality between the containers themselves. So, for example, even though list and vector both have push_back(), there's no interface class, so you can't have a pointer to a push_back()able container. Similarly, you can't extract a common interface to say list and list B*> even though push_back(&b) ought to work for both.

      The C++ Standard Library (there is no such thing as STL any more) is primarily about generic programming, not class-based inheritance. They are orthogonal paradigms. The standard containers aren't designed to be used in class hierarchies. That's not what they're for.

      The interesting thing is that the "ideal" C++ implementation of a semantic tree data structure as found in compilers would want to use both STL and inheritance: the STL would allow inherently ordered and unordered multiplicities to be represented efficiently while hiding the container algorithms (important if a program has 5000 top-level functions, for example). Inheritance would allow the tree to embody the classifications found in programs: for example literals are kinds of expressions, expressions are kinds of statements and so on.

      Actually, I am writing a compiler-like tool in C++ and doing pretty much what you describe here. The standard containers and algorithms work great in this kind of environment. I have found no need to inherit from containers or have some kind of abstracted interface to the containers. I simply write generic code and it works. Even better, I can easily swap out various implementations of containers and algorithms to make space/time tradeoffs, etc.

      It looks painfully apparent that C++0x will not address this "elephant in the room" and is instead content to faff around with syntactical sugar and "small picture" optimisations.

      I'm not sure what elephant you're talking about. Can you clarify?

      --

    80. Re:Maybe they've grown up a bit by David+Greene · · Score: 1

      Any reasonable compiler should make array indexing equivalent to pointer arithmetic. Strength reduction should cause the compiler to produce essentially the same code.

      --

    81. Re:Maybe they've grown up a bit by sim82 · · Score: 1

      yes, that seems to be the common knowledge and i am still avoiding pointer arithmetics where possible (recently i like stl iterators though, as a way to give the compiler (and other humans) as much information as possible about the real intention of the code). And still, replacing the array indexing got me speedups >5% for inner-loop stuff on gcc, on more than one occasion (i don't remember the details using icc).

    82. Re:Maybe they've grown up a bit by David+Greene · · Score: 1

      Interesting. I'm sure the gcc guys would like to see your example. Sometimes the compiler has to make tradeoffs. Strength reduction can in some cases increase register pressure so it's possible that in your case the compiler took a different strategy due to possible register spilling.

      In any event, I have seen far too many codes where the programmer tried to "help" the compiler and ended up obscuring critical information. In my experience it's better to write the code to give the programmer the most information (i.e. express things naturally) and just let the compiler do its job.

      --

    83. Re:Maybe they've grown up a bit by sim82 · · Score: 1

      yes, it is much better to make things clear to other programmers (which most of the time also helps the compiler find potential errors better).
      Without much effort, I only could only reproduce a speedup of about 1.5% using stl iterators vs. array indexing in a micro benchmark (max element in an int-array). The original scenarios are harder to reproduce in an isolated benchmark. Anyway, it is only measurable on intel core/core2/nehalem cpus. On recent amd cpus there is no difference. My original point was to counter the STL-is-100-times-slower-than-anything-else comments, though.

  24. Re:As everyone forgot EGCS vs GCC back in Linux 2. by Pikoro · · Score: 1

    I have a Caldera OpenLinux T-shirt from back in the day. I still wear it around once a week (because it's the only linux tshirt I have)

    --
    "Freedom in the USA is not the ability to do what you want. It is the ability to stop others from doing what THEY want"
  25. 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.

    2. Re:thus a disaster by Anonymous Coward · · Score: 1, 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.

      Well, if you think that planning is only necessary at the start of those decades ...

      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.

      Eventually? Quite likely. Immediately, as in the next two releases ? Just as likely no.

      A group of people working together will not all see the same big picture.

      And this differs how from the situation with the current machinery in GCC?

      ... people cry for Java-style garbage collection...

      ... in contrast to the current GTY(()) machinery already in GCC for the purpose of garbage collection?

      tl;dr
      GCC already has most of the problems you foresee because it is pushing the envelope of what is doable in "plain" C - and there are established processes to deal with that complexity.

    3. Re:thus a disaster by Anonymous Coward · · Score: 0

      The requirements change.

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

      meguwah?! When requirements change you damn well better be planing how to do things. If not no matter how 'good' of compiler/code/library/whatever you use will not be enough in the long run.

      Two best tools I have for coding is my whiteboard and my brain. I use those for plannnnnning. Even 'simple' changes. Hacks build up after awhile and you end up with a fragile code base if you do not think it thru.

      As my old bosses would tell me (and I now tell my junior devs). "If you cant explain to me why it is broken you cant fix it. Then once you can explain it to me you will tell me how to fix it the fast way and then the *RIGHT* way".

    4. Re:thus a disaster by Anonymous Coward · · Score: 0

      GCC already has garbage collection, it has for ages.

      Using subsets of C++ is perfectly reasonable. They'll just reject changelists and patches that contain any usage of features not in the approved subset. Problem solved.

      Seriously--nobody is going to use exceptions in a *compiler*, that's insane. (Actually using C++ exceptions ever, for anything, would be insane -- some people have tried though).

    5. Re:thus a disaster by olau · · Score: 1

      If you think smart pointers are braindead, it's no wonder you have such a bad experience with C++. They're one of the tools for keeping it simple. C++ is much more expressive than Java, it least it used to be, so there are certainly more ways of writing bad code. But also more ways of writing good code - so you can get closer to heaven. :)

    6. Re:thus a disaster by Anonymous Coward · · Score: 0

      my brain is not a free digital signal processor for you

    7. Re:thus a disaster by jallen02 · · Score: 1

      Surely at least one poor individual out there knows every nuance of the language.

    8. Re:thus a disaster by sim82 · · Score: 1

      IMHO no one should use c++ exceptions before reading and understanding at least some parts of GOTW.ca or the nicer version in Herb Sutters's 'exceptional c++' .

    9. Re:thus a disaster by Anonymous Coward · · Score: 0

      boost is the pinnacle of convolution. I will pick plain STL (STLPort) over boost, if I have to pick C++, that is.

    10. Re:thus a disaster by Anonymous Coward · · Score: 0

      Load of horsesh*t!

      If you had programmed in C/C++, you would know that any serious project requires coding conventions (that is probably true in any sane development environment anyway). Those take care of your pet features and your personal quirks. If you want to develop in this team, you make those coding conventions yours; that's your "Venn diagram", period. Can't do that? Can't join the team. Next resume, please!

      There, stopped that for you. Using "industry standard practices" too!

    11. Re:thus a disaster by Anonymous Coward · · Score: 0

      IMHO no one should use c++ exceptions

      Let's just end the sentence there.

  26. 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...
    2. Re:so now I can't grep for functions by swillden · · Score: 1

      You should learn about TAGS (ctags/etags).

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    3. Re:so now I can't grep for functions by Anonymous Coward · · Score: 1, Insightful

      That doesn't work. There's not such entry in the popup menu.

      The popup menu reads:

      Open Terminal
      Open Tab
      ---
      Close Tab
      ---
      Copy
      Paste
      ---
      Change Profile >
      Edit Current Profile
      Show Menubar
      ---
      Input Methods >

      Of course, if your intent was that I should switch to some separate, low-quality environment where actually editing text is lousy but I get some odd menu item with right click, I can tell you that my experience from having tried that is that I lose more time than I gain. The net best situation is to run vim in one window to do the actual editing, and have the bad editing environment available for lookups. I've done a short trial of fully switching to those new-fangled "integrated development environments" - a year or so - but they just didn't work for me.

    4. Re:so now I can't grep for functions by Anonymous Coward · · Score: 1, Insightful

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

      Popup menu?

      You do realize that this is Unix and that quite a few people LIKE using the command line, with editors like emacs or vi, tools like grep and find and sed, with "plain" Makefiles and so on, right?

      Not everybody uses a GUI IDE. For that matter, not everybody WANTS to use a GUI IDE.

    5. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      That might work for your tiny home project. For a major codebase it sucks -- IDEs are way too slow, and C++ is a bitch to parse.

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

      OK, we'll get off your lawn and leave you to it...

      --
      No sig today...
    7. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      Right Click? I can't find this "right click" key on my keyboard.

    8. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      You're not grasping this. What popup menu?

    9. Re:so now I can't grep for functions by shutdown+-p+now · · Score: 1, Flamebait

      You do realize that this is Unix and that quite a few people LIKE using the command line, with editors like emacs or vi, tools like grep and find and sed, with "plain" Makefiles and so on, right?

      Not everybody uses a GUI IDE. For that matter, not everybody WANTS to use a GUI IDE.

      Your IDE (sorry, editor) gets 40 rods to the hogshead, and that's the way you likes it?

    10. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      Well, there are also some people who are into BDSM. The two sets probably overlap very well.

    11. Re:so now I can't grep for functions by GreyWolf3000 · · Score: 1

      What if I need to write a script that iterates through all references to addFloatAndInt? What if the script doesn't know it's looking for references to addFloatAndInt until runtime?

      --
      Slashdot: Where people pretend to be twice as smart as they really are by behaving like children.
    12. Re:so now I can't grep for functions by SheeEttin · · Score: 1

      grep -E 'add\(([0-9.]+)?, ' *.c
      Okay, so that's little over-complicated. You could probably just get away with 'add\([0-9]', if you're looking for use. (If you're looking for declaration, 'int add(', or whatever type it is.)

    13. Re:so now I can't grep for functions by steveha · · Score: 1

      Why do you want me to suffer?

      I want you to suffer for writing pretentious, angsty things like "Why do you want me to suffer?"

      As for the programming stuff, if ease of grepping is the most important thing to you, then go ahead and stick with C. The global namespace will force you to write globally unique function names, which are perfectly greppable.

      I haven't worked on a large C++ project but I have worked on a large Python project, and I can tell you that I didn't "suffer" due to the lack of globally unique function names.

      How often do you need to grep for every reference to a function? And why do you need to do it? I work, all by myself, on a rather large code base, and I can't remember the last time I needed to do this.

      P.S. I'm a command-line fiend, and my favorite development "environment" is vim plus ctags. Nonetheless, I do have access to things like Eclipse, and if I ever need to "refactor" code (example: rename a function, both the definition of it and all calls) I am willing to fire up Eclipse and use the GUI refactor tool. And then, I rebuild my ctags file and go back to using vim to do my main editing work.

      Spend less time yelling at the kids to get off your lawn, and spend more time looking at the available tools.

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    14. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      Because it's fun to watch you whine about it!

    15. Re:so now I can't grep for functions by McGiraf · · Score: 1

      Try to do that without X.

    16. Re:so now I can't grep for functions by Anonymous Coward · · Score: 0

      Uhm, stop being a dumbass

      grep MyClass::add *.c

    17. Re:so now I can't grep for functions by Stiletto · · Score: 1

      I suppose you posted your message by telneting to slashdot and crafting the HTTP message by hand, too...

    18. Re:so now I can't grep for functions by David+Chappell · · Score: 1

      You mean the popup menu in the complicated language-specific tool? Thought so.

  27. Operator overloading is essential by Joce640k · · Score: 1

    Sure it can be abused, if you're overloading operator+ to insert records in a database you're doing it wrong.

    OTOH operator[], operator*, operator-> and even operator are fundamental to data processing - you can't remove them from C++ without doing a lot of harm.

    Anybody who advocates removal of operator overloading has completely missed the point - yes they can be evil but the good far outweighs the bad.

    --
    No sig today...
    1. Re:Operator overloading is essential by J.+J.+Ramsey · · Score: 1

      I remember when I was looking into matrix classes for Java and finding that addition, multiplication, etc. were done by things like "A.plus(B.times(C))" rather than the more readable "A + B*C", because Java lacks operator overloading. In an attempt to simplify Java, its designers made a decision that ended up making certain code needlessly harder to maintain.

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

  29. C++ is better for ANY kind of job. by Joce640k · · Score: 1

    (assuming you've got a decent C++ compiler...)

    Seriously, how can you live without RAII, etc.?

    --
    No sig today...
    1. Re:C++ is better for ANY kind of job. by daid303 · · Score: 1

      RAII? Easy in C, there are functions that create and initialize the memory. Almost all C libraries work that way.

      C syntax: FILE* bla = fopen("bla", "rb");
      Java syntax: File bla = new File("bla", "rb");

    2. Re:C++ is better for ANY kind of job. by Joce640k · · Score: 1

      Yes...but can you tell me when either of those files is closed?

      --
      No sig today...
  30. Obligatory by antifoidulus · · Score: 1

    Wait....C++....standards?

    DOES NOT COMPUTE

    *Head explodes

  31. Re:Virtual functions as mentioned in the link... by Joce640k · · Score: 1

    I don't see what the problem with virtual functions is. He goes on and on about 'added overhead' but the overhead isn't added unless a programmer types the word 'virtual' somewhere in the source code. Presumably the programmer expects to get something in return for typing it... therefore the overhead is acceptable. QED.

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

    Exception handling ... probably not needed in a compiler. A compiler isn't likely to want to recover from a fatal error.

    RTTI ... probably not needed either and usually quite easy to work around for the few cases a compiler might want it.

    --
    No sig today...
  32. Crap by Polizei · · Score: 1

    And, of course, this will slow down the compiler at least twice, maybe even more.
    C++ is good, but C is best. Ever wondered why the kernel is written in C (with lots of assembly spices), not C++?

    1. Re:Crap by multipartmixed · · Score: 1

      > And, of course, this will slow down the compiler at least twice, maybe even more.

      Mozilla's SpiderMonkey JavaScript engine switched from C to C++ about 18 months ago.

      In case you haven't been keeping up, it's a hell of a lot faster than it used to be.

      Now, that said, it takes longer to compile -- but who cares about how longer it takes to compile your compiler. What matters is how fast the resultant compiler is.

      --

      Do daemons dream of electric sleep()?
    2. Re:Crap by bluefoxlucid · · Score: 1

      Mozilla's SpiderMonkey JavaScript engine switched from C to C++ about 18 months ago.

      In case you haven't been keeping up, it's a hell of a lot faster than it used to be.

      It also uses a completely different execution strategy than its predecessor. They didn't just bugfix and translate to C++; they replaced it with a completely different design.

    3. Re:Crap by kthreadd · · Score: 1

      Ever wondered why the kernel is written in C (with lots of assembly spices), not C++?

      It's interesting that you are talking about the kernel since there is quite a few of them, some of which are successfully written in C++. Haiku is a good example that is currently becoming more and more interesting. I'm not saying that C++ would always be a good choice, especially if you already have a large codebase written in a different language like C, but it could definitely work well if used properly from the beginning.

    4. Re:Crap by multipartmixed · · Score: 1

      Even running without the JIT, it is significantly faster. Note that the current JIT only kicks in on loops anyhow (method JIT is still very very alpha quality).

      And I doubt GCC is planning to simply bugfix and and translate to C++ -- the project is likely to be similar: better namespacing, occasional use of templates, RAII, etc - clean up old code as we go, add new code using new idioms as appropriate; produce better code overall because of the richer vocabulary.

      --

      Do daemons dream of electric sleep()?
    5. Re:Crap by Anonymous Coward · · Score: 0

      Because you can't teach an old dog new tricks. And because exception propagation in kernels might be a little bit problematic. But for userspace programs C++ is unbeatable.

    6. 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...
    7. Re:Crap by cpghost · · Score: 1

      Another good example of a very performant microkernel written in C++ is L4Ka.

      --
      cpghost at Cordula's Web.
    8. Re:Crap by bzipitidoo · · Score: 1

      stdio vs iostream? Or don't those count as parts of C and C++ respectively?

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
    9. Re:Crap by LingNoi · · Score: 1

      Pardon my ignorance but don't they WRITE the compiler? If it's slowing down then it's their own fault for not making it generate better code in the first place.

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

  33. 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."
  34. Free software forcing proprietary software out :( by jonaskoelker · · Score: 1

    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.

    There's a sig I see around here, about religions: (paraphrased) "If you need government to enforce your religious rules, what does that say about the strength of your message?"

    If we* need to make it impossible for proprietary software to work with free software in order to sell** the free software, what does that say about the strength of our message and our ability to compete, feature/tech-wise? :(

    I give all my moral support*** to the GNU project, which has the goal of enabling people to use only Free Software(tm) and Get Their Shit Done(tm). Making free software worse for the purpose of making proprietary software more worse (say, as in non-existent) runs counter to the purpose of the GNU project. Don't do that. Be pro-free, not anti-proprietary.

    * The "freetards" :D
    ** lit. "make people use", fig. as in "selling [someone on] an idea".
    *** including by wearing @gnu.org in my mail address---but I don't represent anyone but myself.

  35. Learn something about the language. by Anonymous Coward · · Score: 0

    Obj-C is a pure superset of C, unlike C++. This means you can compile straight C programs with no changes. This means it is just as fast and typed as you want it to be up to the speed of C. Learn something about the language before commenting on it.

    1. Re:Learn something about the language. by Cyberax · · Score: 1

      I'm talking about Objective-C features which are superset of C. Almost all of them come at a significant price.

  36. GCC C++ itself?? by scharkalvin · · Score: 1

    How could they have written a complier for a language they don't know? You do realize that GCC already does support C++? This means the GNU guys are admitting they don't know the language that they already wrote a complier for? How good a C++ complier could GCC be?

    1. Re:GCC C++ itself?? by Vairon · · Score: 1

      GCC stands for the GNU Compiler Collection. It consists of compilers for C, C++, Objective-C, Fortran, Java, and Ada. Those compilers share a lot of code. Not all GCC programmers know all 6 languages. However they do all know C. What's been decided is that they will now have the option of using C++. All that's left is to decide what subset of C++ features are useful and easy to use effectively for both the GCC programmers who know C++ well and those who don't.

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

    1. Re:Hooray for a slower compiler! by JoeMerchant · · Score: 1

      I'm assuming that any addition of C++ code will be tested against the existing implementations for performance, and if it is seriously lacking, the existing implementation will be kept until the C++ code can be "brought up to speed."

    2. Re:Hooray for a slower compiler! by noidentity · · Score: 1

      Yeah, hooray for a compiler that can be developed with fewer resources, this freeing more for improving its performance or correctness. Seriously, you can start with some C code and carefully make use of just a few C++ features in order to improve the code (easier to maintain, improve performance without hurting maintainability much, etc.). Read that last sentence carefully; I did not mention any particular C++ features. I regularly use a subset of C++ and avoid the downsides people regularly talk about and that I see in "extreme C++" code.

    3. Re:Hooray for a slower compiler! by Anonymous Coward · · Score: 0

      Virtual tables are completely resolved at compile time and at load time of the executable to rebase memory offsets. When an object of a polymorphic type in C++ is constructed, it has a single hidden vtable pointer that is set to the correct vtable. There is no confusion over pure virtuals, there is no time spent running through the symbol table. It's all statically bound, not late bound like in languages such as Objective-C or Visual Basic. The equivalent in C would be:


      struct foo;

      struct foo_vtable
      {
              int (*evalulate)(struct foo* f);
      };

      struct foo
      {
              struct foo_vtable* vtable;
              int value;
      };

      int foo_evalulate(struct foo* f) {
              return value;
      }

      foo_vtable foo_vtable_record = { &foo_evaluate };

      int bar_evalulate(struct foo* f) {
              return value + 1;
      }

      foo_vtable bar_vtable_record = { &bar_evaluate };

      int main() {
              foo a = { &foo_vtable_record, 1 };
              foo b = { &bar_vtable_record, 1 };
              printf("a: %d\n", a.vtable->evalulate()); // prints out "a: 1"
              printf("b: %d\n", b.vtable->evalulate()); // prints out "b: 2"
              return 0;
      }

      It's actually quite fast, just a pointer dereference and a table lookup. The only thing possibly slow about it is that accessing the vtable can cause cache thrashing depending on your target hardware and what you're doing, as usually you only have a single vtable per concrete class type in the program's constant data segment.

    4. Re:Hooray for a slower compiler! by Joce640k · · Score: 1

      This assuming there'll actually be a performance problem.

      In my experience the "C++ is slower then C" crowd can never manage to put their money where their mouth is.

      --
      No sig today...
    5. Re:Hooray for a slower compiler! by bluefoxlucid · · Score: 1

      In my experience the "C++ is slower then C" crowd can never manage to put their money where their mouth is.

      Michael Meeks' primary efforts in making OOo take less than 13 seconds to load involve finding ways to get around the gazillions of piles of namespacing and classing shit that the linker has to deal with due to C++. Roughly 70%-90% of the load time is overhead that's caused by the use of too many classes and too many virtual functions.

    6. Re:Hooray for a slower compiler! by JoeMerchant · · Score: 1

      I "lived it" once back in 1996, the then C compilers were pushing out about 2x the performance of the then C++ compilers for similar tasks. Of course, it's always an apples to oranges comparison, but our ported C++ app performed at 1/2 the speed of it's C predecessor (same programmer on both).

      Compilers have improved, hopefully that gap has narrowed. Five years earlier, the C++ compilers for PCs couldn't produce stable executables (and the hardware I had access to that had "stable" C++ compilers - a big mainframe - was itself down half the time... blame the admin, but it was still unaccessable to the users.)

      For me, the ease of development in C++ is why I'm there (in Qt libraries, now.) Even if the code runs at 1/2 speed, it's worth it when the development time is cut by 50% (or more).

    7. Re:Hooray for a slower compiler! by onefriedrice · · Score: 1

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

      What does any of that have to do with the language the compiler is written in? It's not like the compiler is being recompiled every time you build X11. If you're trying to make the point that programs written in C++ are considerably slower than those written in C, you've still got some explaining to do.

      --
      This author takes full ownership and responsibility for the unpopular opinions outlined above.
    8. Re:Hooray for a slower compiler! by mr+exploiter · · Score: 1

      Maybe now that they will eat their own dogfood they will finally make a fast compiler.

    9. Re:Hooray for a slower compiler! by bluefoxlucid · · Score: 1

      A large amount of overhead is spent in the dynamic linker. With C, the amount of garbage to trudge through is minimal; with C++, it's huge. A modified dynamic linker is able to load OpenOffice.org from scratch in 2 seconds, where the original loaded in 13 seconds; however, it broke some fundamental guarantees of the dynamic linker (symbol interposing didn't work anymore, and couldn't).

      Note that the same modifications made C based programs load extremely fast, too; but with C++, the symbol names could be 10 times longer, and the sheer volume of similarly-prefixed symbol names exploded. This is because C++ mangles everything into namespaces; it expands class definitions massively; inheritance causes a lot of interesting things with virtual tables, which then has to be resolved at load time (not compile time, as another commenter said), causing a lot of work for the dynamic linker; and so on.

      If gcc (the C compiler) takes 0.05 seconds to resolve its symbols, and cpp (the C preprocessor) takes 0.05 seconds to resolve its symbols, and you #include headers which #include other headers which together include an average of 20 headers; then total, your overhead from dynamic linking (of the compiler) to compile one C file is 1.05 seconds. If suddenly the C compiler and preprocessor have to resolve all kinds of virtual pointers and trudge through symbols that are 1000-2000 characters long, doing millions of character comparisons instead of hundreds for each and every symbol, with thousands of symbols instead of hundreds; then you may experience overheads of 0.15 seconds, and now it takes 3.15 seconds of such overhead.

      You see the implications already: The difference in dynamic link time is 0.10 seconds, negligible. Yet the binaries are run again and again, and the additional time taken is several seconds. On top of that, the process of building anything mildly complex may involve interpreting hundreds or thousands of source files; and in the process, the C preprocessor may be invoked several times for each source file, or in very complex projects it may ultimately wind up running through hundreds of header files for every source file it touches (see: Linux Kernel; also think of why headers wrap their bodies in #ifdef statements.. due to headers including other headers, leading to multiple inclusion, letting the C preprocessor reduce the body to an empty file). Millions of tenths of a second is still hundreds of thousands of seconds.

  38. So... by Anonymous Coward · · Score: 0

    when does the file handle get freed? Ass.

  39. from experience debugging compilers by Anonymous Coward · · Score: 0

    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.

    Actually, not so much as you might think.

    Over a lifetime of programming, I've spent far FAR too much time debugging problems in compilers (from UCSD, IBM, Sun and even GNU compilers) and "MyClassAddFloatAndInt()" is inevitably going to be mangled at the Assembly or machine code layer where you will work to identify and demonstrate most compiler bugs.

  40. 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.
    1. Re:Not all that slow by Anonymous Coward · · Score: 0

      The thing about Obj-C is where speed really matters, the code can be written in pure C.

      Though I would think if the gcc devs are going to use a thin layer over C, instead of obj-c they would be more likely to choose vala.

    2. Re:Not all that slow by Cyberax · · Score: 1

      "And as for being deterministic: why would a compiler have to be deterministic?"

      For completely reproducible compiler results.

    3. Re:Not all that slow by ultranova · · Score: 1

      Seeing how garbage collection deals with reclaiming unreferenced memory, it should never interfere with compiler output. The only way it could is that you are somehow using that memory, suggesting that you have a buffer overflow or pointer arithmetic somewhere (since dangling pointers should be impossible with GC). This, in turn, is a bug and has nothing to do with GC itself.

      --

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

    4. Re:Not all that slow by Cyberax · · Score: 1

      In theory.

      In practice, a lot of garbage collectors collect _some_ unreferenced memory depending on a lot of factors.

      Also, don't forget about bugs caused by improper GC usage (like failing to mark reference as used). This has nothing to do with GC but detection of these bugs might be greatly complicated by a non-deterministic GC.

    5. Re:Not all that slow by ultranova · · Score: 1

      In practice, a lot of garbage collectors collect _some_ unreferenced memory depending on a lot of factors.

      Yes, and it shouldn't affect the output of a program at all if there's unreferenced but not yet reclaimed memory areas in its address space.

      Also, don't forget about bugs caused by improper GC usage (like failing to mark reference as used). This has nothing to do with GC but detection of these bugs might be greatly complicated by a non-deterministic GC.

      Um, what? The whole point of GC is that you don't have to mark references as used or unused, you simply either have them or not. The only way that could fail is if you held a pointer pointing directly to a table entry or something.

      Are you perhaps confusing garbage collection with some kind of reference counting scheme?

      --

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

    6. Re:Not all that slow by Cyberax · · Score: 1

      "Um, what? The whole point of GC is that you don't have to mark references as used or unused, you simply either have them or not. The only way that could fail is if you held a pointer pointing directly to a table entry or something."

      Wrong. You have to mark a reference as 'used' if it's passed to a non-GC-aware code.

      For example, if you attach a reference to a GC-ed structure to an object which is not scanned by a GC you'll definitely get an error when GC collects this object.

      And there are other more subtle failure modes (like saving a last reference to the object on a stack variable and triggering GC by allocating another object).

      And there's even more fun if you use a compacting GC :)

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

    1. Re:More eyeballs by Anonymous Coward · · Score: 0

      Indeed, which is an incredibly good thing, but not if you don't know about it. MSVC's STL implementation provides iterator debugging (debug mode) and checked iterators (debug/release modes) by default. This can dramatically slow down a program, and is something many inexperienced C++ programmers fail to disable when profiling, resulting in inaccurate timings.

  42. 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,
  43. welcome to 1985! by ynohoo · · Score: 1

    Nice to see they are not easily swayed by the "fashion victims" of more recent languages.

    1. Re:welcome to 1985! by iggymanz · · Score: 1

      same to you about your sig

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

  44. Re:Virtual functions as mentioned in the link... by Joce640k · · Score: 1

    I thought compilers would chop the incoming text up into lots of little strings and put them in an array of tokens, to me that says std::string and dynamically growing containers - much more robust than malloc and strcpy.

    The expression evaluator will need a stack along with typed data items (int, float, double, etc). C++ can make that sort of thing much neater.

    If you dig into it, I'm sure there's many places where C++ would remove a lot of lines of code from a compiler.

    --
    No sig today...
  45. Boom by Anonymous Coward · · Score: 0

    Someone's bound to be shot in the foot for this.

  46. Grace Hopper = COBOL (some "FYI")... apk by Anonymous Coward · · Score: 0

    "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." - by mog007 (677810) on Tuesday June 01, @07:51AM (#32416784)

    See subject-line above, & this URL:

    http://www.jamesshuggins.com/h/tek1/grace_hopper.htm

    (IIRC, also/additionally? The lady's also an admiral too!)

    APK

    P.S.=> It's often said there aren't many women in computing, & compared to the male population involved in it? Typically, it's true! HOWEVER - When there is a woman involved in computing? They surely make a HUGE showing for females' sake (imo also, another one is my fellow polish-person, in Joanna Rutkowska also, & more currently (albeit moreso in the realm of computer security, but, she's far from a slouch in coding also))... apk

  47. bootstrapping... by Anonymous Coward · · Score: 1, Interesting

    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.

    1. Re:bootstrapping... by sohp · · Score: 1

      I had to bootstrap gcc once. I was simultaneously fascinated and repulsed by the magical contortions required to go from no compiler to full compiler with libraries and toolchain.

      Oh, and you kids GIT OFF MAH LAWN!

  48. Static libstdc++ is inefficient by tepples · · Score: 1

    C++ can be very lean and mean indeed.

    Can be != is. A statically linked C++ hello world program using <iostream> is still on the order of a quarter megabyte even on recent versions of g++ and libstdc++. This hurts when you want to use C++ features on a memory-constrained embedded system. Consider a handheld computer with 288 KiB of RAM that sold tens of millions of units between 2001 and 2006. If the libraries needed to run hello world eat up all the RAM, how are you going to fit the application?

    1. Re:Static libstdc++ is inefficient by shutdown+-p+now · · Score: 1

      iostream is not a particularly good example, as it's one of the worst C++ libraries in terms of bloat. The reason is that it combines two programming models - it has an extensive inheritance hierarchy, with multiple and virtual inheritance and virtual methods, on one hand, and it is templated on the other hand. Templates + plenty of virtual methods = bloat in C++, that has always been the case. It's just bad design (for many reasons, this being but one).

      The rest of STL is much, much more lightweight. When using containers, for example, especially the simpler ones such as vector or list, it's not uncommon to see the code inlined entirely, and tightly optimized for every spot where inlining happens.

    2. Re:Static libstdc++ is inefficient by tepples · · Score: 1

      iostream is not a particularly good example, as it's one of the worst C++ libraries in terms of bloat.

      In that case, lesson 1 of any C++ book teaches a bad example. That should tell you something about the language.

    3. Re:Static libstdc++ is inefficient by shutdown+-p+now · · Score: 1

      The language is a classic case of design-by-committee. That doesn't mean that it doesn't have its bright sides, and in particular, you don't have to use all its parts. Using iostreams over something else just for the sake of using them is rather pointless.

  49. gcc C "Hello World!" = 11kB, gcc C++ = ++? by Anonymous Coward · · Score: 0

    "Hello World" pulling in glibc non-necessarily...
    http://developers.slashdot.org/article.pl?sid=10/03/16/2216258 if bloat & bug-interaction is what they require, they're gonna be clobbered by it, and so are we who depend on the toolset.

    Fashion isn't intrinsically intelligent: many a species has gained a Darwin-award for socially-pushed change...

    ( if I'm wrong, then good: state how, so we all can see truth. I'm just going on what understanding I got )

  50. Recording Industry Association of America? by tepples · · Score: 1

    There's no equivalent to RIAA in C

    That's only because the standard C library has no audio output facility. Did you mean RAII?

    there's also no equivalent to stack unwinding or many of the other C++ constructs which are central to good C++ programming.

    But how big is the library support for those C++ constructs? Once you #include <iostream> and reference cout, your statically linked hello world already almost fills RAM of your elevator controller. Do you want to see byte counts for a static hello-iostream.cpp on two different platforms?

    1. Re:Recording Industry Association of America? by TheSunborn · · Score: 1

      That is not really because of c++, but due to a really really bad linker which link in far to many methods which are newer called. (And I seems to remember that gcc on linux have the same problem with some c libraries).

    2. Re:Recording Industry Association of America? by tepples · · Score: 1

      That is not really because of c++, but due to a really really bad linker which link in far to many methods which are newer called.

      That and a constructor for the stream that calls the constructors for date, time, and money aspects of the stream's locale even if the program never outputs a date, time, or money type.

  51. std::nothrow by tepples · · Score: 1

    ability to declare variables in the middle of code blocks

    That's been in C for the past decade.

    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.

    In C++, you pay for what you use. If you don't throw, and you don't link to a library that throws, then you won't have exceptions. I guess their problem is that the standard library uses the version of operator new that throws std::bad_alloc on failure rather than the version that returns a null pointer.

    Maybe they don't want function overloading

    You can disable overloading for a function by putting extern "C" before the name of the function's return type.

    Extended initializers

    Something like that is already in C99.

  52. Can the C based versions be labeled clearly? by bsharma · · Score: 1

    Can the C based versions be labeled clearly for those who prefer a gcc written in C only? If this is not possible, it may be a good idea to create a fork for gcc in C for those who may need it. Ideally, a compiler flag that can switch to C only version if requested would be good.

    1. Re:Can the C based versions be labeled clearly? by TheSunborn · · Score: 1

      Why would you or I as gcc users care about if gcc is written in c or c++ ?

    2. Re:Can the C based versions be labeled clearly? by bsharma · · Score: 1

      Well, as the discussion above demonstrates, there are plenty of people who suspect the quality of gcc (yes, that means quality of compiled code - read bugs introduced by the compiler) will go down after gcc starts being written in c++. If so, they have the option, in the full spirit of openness, to keep the c based gcc alive as long as their lack of trust in the c++ based gcc remains. Once that trust is acquired, say after plenty of people use c++ based gcc in building critical systems for 10 or 20 years. So, by 2030, this can all be forgotten and studied as an amusing transition. However, if a rocket blows up or a reactor melts down or pacemakers fail (due to a bug introduced by c++ based gcc), software designers don't have to feel the sky has fallen. (the way petroleum engineers feel now about the gulf oil leak). but switch to the good old, trusted and proven, c based gcc for their next project.

    3. Re:Can the C based versions be labeled clearly? by shutdown+-p+now · · Score: 1

      Can the C based versions be labeled clearly for those who prefer a gcc written in C only? If this is not possible, it may be a good idea to create a fork for gcc in C for those who may need it. Ideally, a compiler flag that can switch to C only version if requested would be good.

      "This GCC build is certified organic."

    4. Re:Can the C based versions be labeled clearly? by hazah · · Score: 1

      The people choosing their compiler version based on the language its written on are doing it wrong. It's not the language in which it is written, it is the quality of the written piece that matters!

    5. Re:Can the C based versions be labeled clearly? by bsharma · · Score: 1

      What if the language gcc is written in creates new subtle bugs that wont be caught by the test system that has been tweaked over the years to catch code generation bugs of previous (c based) gcc versions? Till the test system matures enough to catch the new family of c++ assisted code generation bugs, it is arguable that high reliability and safety critical systems avoid using the new generation of (c++ using) gcc.

    6. Re:Can the C based versions be labeled clearly? by hazah · · Score: 1

      A 'language' cannot introduce bugs. An implementation of said language can. As such, you must be smart about your choice of the implementation and the subtle bugs it can introduce.

  53. Why not Go or Java? by AxelTorvalds · · Score: 1

    Seeing as how GCC now supports them both, why not use one of them instead?

    1. Re:Why not Go or Java? by TheSunborn · · Score: 1

      Because then they would have to rewrite the entire compiler. The point with using c++ is that gcc can already be compiled with a c++ compiler so they can now start using the c++ without a total rewrite/redesign.

    2. Re:Why not Go or Java? by turgid · · Score: 1

      The point with using c++ is that gcc can already be compiled with a c++ compiler so they can now start using the c++ without a total rewrite/redesign.

      No.

      C and C++ diverged many years ago. C++ is not a strict superset of C. You can not compile a C program with a C++ compiler and expect it to behave correctly in general. Yes, there may be ways of hacking around it, but that would by definition lead to complex and unmaintainable code.

      C++ is not even a solution looking for a problem. It is too difficult for human beings to use effectively, and there are still many deficiencies in the official language.

      gcc is a critical piece of infrastructure in the Free and Open Source world. This is a disaster waiting to happen.

    3. Re:Why not Go or Java? by jdennett · · Score: 1

      Yes: GCC has, in fact, been bootstrapped with a C++ compiler, and works the same that way as when compiled with a C compiler. It took some work, but that work has been done.

      It arguably leads to more maintainable code, because you get C++'s stronger type checking.

  54. those reasons don't apply (IMHO) by YesIAmAScript · · Score: 1

    Having done a little work with this, I think kernels are written in C because of issues with the runtime library. The C++ runtime is more complex to get up and working, and a kernel needs a different runtime library than the rest of the system because it has a different memory map and it doesn't make syscalls to the kernel to make things happen at the back.

    Also, in the kernel there are plenty of places where you don't want anything happening between point A and point B that allocate memory or touch user space or manipulate semaphores or whatever, because you're in a critical section. Well, part of the whole design of C++ is a single statement can turn into dozens or hundreds, and often these statements will auto-allocate (and de-allocate) memory for you or use other resources. So you'd have to be real careful if you used C++, so careful that I'm not sure you get much from C++ except namespaces.

    So in short, I think the reasons kernels don't use C++ cannot be directly applied to a compiler. It has its own reasons (primarily bootstrapping) though.

    Also, kernels don't use much assembly, I'd say "lots of assembly spices" is an exaggeration. You can never get the amount of assembly down to 0, but neither do you use it that much.

    --
    http://lkml.org/lkml/2005/8/20/95
  55. Modern Myths by Mybrid · · Score: 1

    There is a myth out there that object oriented code produces better quality code then procedural programming.

    I say myth because scientifically it has never been proven that code quality improves with compiler discipline.

    All claims about less bugs per lines of code, easier to maintain, etc are purely anecdotal and speculative. When I studied this back in the early 1990s the primary impedance to any objective analysis comparing like for like were cost prohibitive. Any effort that involved a change in language also incorporated a change in design. People who wrote the original implementation were replaced, etc. etc.

    One could look at this as a teaching moment.

    Someone needs to step up and prove that compiler or language discipline increases code quality holding the developer constant.

    The claim is that a programmer using a different compiler or language produces better quality code. It has been shown scientifically that a C compiler will mostly produce better performing code than code written in assembly. It has never been proven that compiler discipline can make a better programmer. If it has been proven than someone should be easily able to point that proof the to GCC crowd for them to use as an arbitrator for where to draw the C++ line.

    The only argument that makes sense with respect to object oriented languages is that they afford a toolkit for upfront design. The large project architect has tools to layout the design for the implementers to essentially fill in the blank. Stroustrup predicates his entire C++ book on this point.

    However, it doesn't appear the design features of C++ are the objective here. The objective here is code quality via better syntax, and is this is a claim that has never proven. Its a modern myth.

    This is really not a discussion about C++ vs. C, but rather the modern myth that any given developer produces better quality code by compiler discipline.

    1. Re:Modern Myths by Anonymous Coward · · Score: 0

      > It has been shown scientifically that a C compiler will mostly produce better performing code than code written in assembly.
      O RLY? I wasn't aware of the c2magic_pixie_dust compiler. Given that all compilers I know output code that maps 1:1 to assembly language, I would like to know how it manages to produce better code than assembly language.
      So, it can produce better code than many/most people acquainted with assembly. These same mediocre people can grab the -S output and Agner Fogg's Assembly Optimization guides and beat the "almost perfect" compiler any time.
      I use C for portability and readability, and also to save typing, but it is not faster than assembly because that is just impossible. For that matter it isn't even as fast as hand assembled code by someone knowing what he is doing could produce, and -O3 tends to produce invalid code. so maybe in a few decades you have a point, just not now.

  56. JavaScript! by shutdown+-p+now · · Score: 1

    Yeah, but have they tried JavaScript?

  57. Re: Linus by ibsteve2u · · Score: 1

    [Linus] sustained that C++ is utter crap

    I thought he said C++ is an overloaded piece of shit?

    --
    Orwell: "In a Time of Universal Deceit, telling the Truth is a Revolutionary Act"
  58. The basic trouble with C++ by Animats · · Score: 1

    It's sad. C++ has major problems, which are well known. The fundamental problem is that C++ has hiding without memory safety. C++ is unique among major languages in that respect. There are languages with no hiding, (C, assembler) and languages with both hiding and memory safety (Java, Delphi, Go, D, Ada, Modula, Erlang, Eiffel, and all the "scripting" languages).

    The C++ committee, and Strostrup, are in denial about this. They're off in template la-la land, trying to abuse the template system into a compile-time interpreter.

    C has its own problems. The basic one is that you lie to the language about how big things are. A string parameter is declared as "char *", not "char[n]". So the language has no idea how big objects are. It doesn't require garbage collection or array descriptors to fix this. It just requires a declaration syntax where you can talk about the size of the arrays you're passing around. This fundamental defect in C is the cause of most buffer overflows. (Technical discussion: C should have had array parameter declarations like int read(int fd, char[n]& buf, size_t n); rather than int read(int fd, char* buf, size_t n); Then the language knows how big the array is. This could be extended to structs, etc. so that whenever you have an array, there's an expression known to the compiler that defines its size. This allows subscript checking.)

    C++ tries to paper this over with collection classes, but the mold always seeps through the wallpaper. Too often, you need a raw pointer, which breaks what little protection the collection classes provide.

  59. Gcc moving to c++ is going to be disaster. by Anonymous Coward · · Score: 0

    I've been there and seen how it works. We had C++ project which used to have strict rules what kind of stuff you're allowed to insert. It starts by people following the rules, but they silently think the rules not worth the effort; but immediately when you give green light to make the rules less restrictive -- like gcc going to c++ is going to make all the wannabe c++ programmers want _all_ their restrictions gone.

    Here's why:
      1) First they will have lots of rules what kind of code they allow
      2) But people will ignore those rules, because why can't we use _all_ of C++, if they allow _any_ of C++ code in.
      3) Next their code will be full of STL and all kinds of stuff that interacts very badly with existing C code
      4) then their compile times will be very slow. It will take lots of time to compile it. Developers gets bored because they're not developing but only waiting for computer to compile the code.
      5) then the project dies.

    I've seen it happen before, and the this news about gcc going to c++ sounds exactly the same pattern. The reason they need to go to c++ is because they get complaints about the restrictions that they're enforcing. But it's big mistake to remove the restrictions or part of it. It'll not stop there -- people will want all their "unnecessary" restrictions away. And that has a chance of killing the project.

  60. STL by Meeni · · Score: 1

    There are also plenty of lean and efficient vector/list/hashtable libraries in C. I hardly see the point of promoting the STL. Moreover, GCC probably already feature lists and stuffs, and has been for years. Therefore, I don't see exactly what is the point at saying that STL is more this and that, compared to what already works in GCC ?

  61. Re:As everyone forgot EGCS vs GCC back in Linux 2. by turgid · · Score: 1

    I had a Caldera OpenLinux CD. I gave it to the Jehova's Witnesses one Sunday morning when they called round in exchange for a leaflet about Armageddon.

  62. Behold, a Pasty Dorrito-encrusted horse. by Anonymous Coward · · Score: 0

    OhyouwinagainInternet.jpg

  63. Re:Virtual functions as mentioned in the link... by Rockoon · · Score: 1

    I thought compilers would chop the incoming text up into lots of little strings

    Thats the abstraction. You know that this can be done in many ways, right?

    It *could* use your sloppy and memory-hungry std:string crap...

    ...or it could use a hash table to associate the token with a number assigned to it, and pair that with an auxiliary array (indexed by that number) that stores information about the token.

    In short, you are basically educated in step one of abstraction, but not the implementation.

    The expression evaluator will need a stack along with typed data items (int, float, double, etc). C++ can make that sort of thing much neater.

    First, regular old C was designed to make implementing stacks simple. Pre-and-Post increment-and-decrement is absolutely all you need .. in short, the damn thing has operators specifically for stacks and queues. I will repeat the assertion that the only thing STL brings to the table is generic containers. The key word is generic and you havent justified a need for them.

    Your datatype argument is not well educated, I am afraid, since STL containers are only generic prior to compile-time. In short, they are not run time generics so STL doesn't add anything for a compiler in that regard. The compile needs to treat things as arbitrary datatypes at runtime, and in that vein OO in general is no better than flag/feature bits and function pointers. Either way it needs to perform tests, branch to specific processing or output routines, etc..

    If you dig into it, I'm sure there's many places where C++ would remove a lot of lines of code from a compiler.

    Why don't you think that its just as likely that it will require more lines of code? You need to think this through, because OO is most certainly not heralded for enabling shorter program sources.

    --
    "His name was James Damore."
  64. Re:OOP in C? It cannot B ! ;-) by Pseudonym · · Score: 1

    Good luck implementing exception handling.

    --
    sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
  65. If they test it, they'll see that you're wrong. by Anonymous Coward · · Score: 0

    If you test it, you'll also see that you're wrong, unless you're running debug builds (in which case you're not comparing apples to apples, as the STL versions will have massively better debugging capabilities).

    Badly written code is slower than well-written code for sure, but there's nothing about STL that makes you write bad code. (Nor does it stop you writing bad code.)

  66. const was in C89, aka ANSI C by jdennett · · Score: 1

    The ANSI C committee adopted const from C++ in time for the first ANSI C standard, 21 years ago (sadly not calling it "readonly").

    (You make a valid point about not having to use every C++ feature to get benefits from using some, and I believe that the plan is to be conservative in introducing features that are helpful while avoiding more controversial or complex features.)

  67. Self hosting by krischik · · Score: 1

    You use a cross compiler. But it is painful - GNU Ada is self hosted and moving Ada to a new platform is quite painful. But once done it's a lot more fun. Why should Ada, Fortran or C++ advocates be forced to use C to improver their favourite compiler.

    And maybe the move to C++ also means better cross compiler support.

    Anyway: self hosted Fortran next!

  68. Ada is allready self hosted by krischik · · Score: 1

    Actually not all gcc is written in C. The Ada front-end is written in Ada. I think it is the way to go, all language front-ends should be self hosted.

  69. rocket blows up or a reactor melts by krischik · · Score: 1

    rockets and reactor software should neither be written in C nor in C++. For those you should use SPARK Ada:

    http://en.wikipedia.org/wiki/SPARK_(programming_language)

    And funnily enough: GCC Ada is written in Ada. Because the real (not pseudo) high integrity developers won't trust a language which (easily) allows to cast a pointer to an integer.

  70. Name mangling is deliberately different by jdennett · · Score: 1

    Different name mangling between different compilers is deliberate, and a good thing: it stops you linking together code that uses incompatible ABIs, and then getting strange crashes.

    Now, if you want to complain that it took too long to standardize ABIs for C++, and that it's too hard, and that they're not stable enough, then you might well be able to make a pretty strong case, but that's a different thing. If your ABIs don't match, you shouldn't make your name mangling match.

    (Incidentally, if you code in a sane way then the implicit copy operations _almost_ always do the right thing. It would still be better if we had to explicitly enable them, but that would have broken C compatibility, or made struct vs class into two different worlds.)

    1. Re:Name mangling is deliberately different by daid303 · · Score: 1

      made struct vs class into two different worlds.

      And you say it like that's a bad thing?

    2. Re:Name mangling is deliberately different by Anonymous Coward · · Score: 0

      made struct vs class into two different worlds.

      And you say it like that's a bad thing?

      ;)

      It was a deliberate, and defensible, position. Many languages have gone the other way (D, C#), though over time they've added more functionality to their value types (structs), bringing them closer in expressive power to full classes. Other languages only have one or the other.

      Having structs and classes be two completely different things has pros and cons. I believe that Bjarne made a pragmatic decision that doing it this way would smooth evolution for users.

  71. Bitwise copy is C semantics, not C++ by jdennett · · Score: 1

    C makes bitwise copies. C++ makes memberwise copies (and in simple cases, can optimize that to a bit copy). In C++ you'd hold a smart pointer, and copying that would do the right thing (whatever the smart pointer defines it to do: ref counting, causing a compilation error, making a copy of the target).

    Copy operations in C++ would probably not be implicit, if it weren't for the fact that they're implicit in C.

  72. STL isn't a container library by jdennett · · Score: 1

    It is a library for generic algorithms, decoupled from data structures via STL's notion of iterators (which is rather different from GoF iterators). As a proof of concept it happens to provide some containers that work pretty well.

  73. Refutation by jdennett · · Score: 1

    There are many problems with your example.

    • You can't do non-trivial initialization in the constructor because initializer syntax is not turing complete. Most C++ style guides (such as Google's) suggest using a separate init() function, so it isn't really less lines of code.
    • A constructor can't fail without throwing an exception. Assuming you don't allow exceptions, your class now needs an internal dead state. This is the case even if you use a separate init(), because the destructor needs to know whether init() was successful (unless of course you use a separate destroy(), making this pointless.)
    • A destructor can't fail at all. There is no way to indicate failure; you can't throw an exception because the destructor might be called during stack unwinding from another exception. What if the destructor fails to flush a buffer? The C version can simply return a boolean to indicate this.
    • There is no way to indicate that MyClass should not be inherited, so to allow deletion through a base class pointer (a requirement to satisfy the Liskov substitution principle), your destructor should be virtual. This adds overhead to the class itself, and adds a lot of overhead at the call site if the runtime type cannot be statically inferred.
    • You now need implement (or at least declare private) copy constructors and operator=. Developers expect C++ objects to be copyable, and standard containers require it.

    Don't you see what is going on here? Even the most trivial feature of C++, constructors, are horribly ridden with complications. C++ is a language of never-ending surprises, gotchas, land mines. It's a trap.

    Let's knock those down one at a time.

    • From the constructor's initialization list you can call arbitrary functions. Whether you should or not is another matter, but it's certainly possible.
    • You can make your constructor take a bool& succeeded parameter if you really can't allow exceptions. (Or even an Error reference.) No worse than C, often better.
    • Destructors can and do fail, but if you want to detect failure instead of ignoring it you should call a function explicitly. No worse than C, often better.
    • You can indicate in a number of ways that MyClass cannot be inherited from; documentation should suffice, but there is also a silly trick you can use if you think that technical solutions to social problems are a good idea. Even without that, you don't need to allow deletion through the base class; just make its destructor protected.
    • If you use resource classes to hold resources (which, it turns out, makes your code cleaner and simpler) then you don't need to do anything about implementing copy operations; the compiler just does the right thing. For your resource classes, you do need to implement them, but there are relatively few such classes, and they're simple.
    1. Re:Refutation by physicsnick · · Score: 1

      Yes, you've managed to find workarounds to all of these issues. There are of course ways to work around them. People do use C++ to get real work done; I have used it successfully many times in the past.

      The point is that you have to *know* about all of these issues in order to use just this one feature effectively, without introducing subtle bugs, performance issues, or design problems.

      Your solutions will mostly work of course but they are not terribly compelling. We might as well keep going:

      • Calling arbitrary functions in constructors might work, but you can't return multiple values to use as different constructor arguments, so there are more hacks to be done there.
      • Taking a bool& is pointless; you still need a dead-state for the destructor, so you may as well make a separate method to test for the dead-state after the constructor is run. (Good style also generally dictates you should never use non-const reference parameters; use pointers for out parameters to highlight that they will be written to.)
      • Making its destructor protected prevents the class from being destroyed at all unless it is subclassed; the example GGP gave would longer work. I'm not sure what you meant be this. I do agree that documentation should suffice, but tools like -Weffc++ will still warn about it (and rightfully so.)
      • I am not sure what you mean by resource classes. All I'm saying is that if MyClass contains a pointer and you forget to create a copy constructor, the compiler will do so implicitly, and your class will break horribly somewhere down the line.

      Again, these are not insurmountable issues. They are just many things you need to be aware of in order to use constructors effectively. No other language has such land mines in such a simple feature as object constructors.

    2. Re:Refutation by Anonymous Coward · · Score: 0

      I wasn't just "finding workarounds", except in the one case where we decide to artificially disallow use of exceptions (which are the mechanism that most OO languages now use to signal construction failures).

      • Yes, there's a known issue with not having forwarding constructors in C++98; C++0x will fix that.
      • You don't always need a separate dead state, and creating one is a waste of storage for objects that stay around once they're known to have been created successfully.
      • Opinions vary on passing mutable parameters via non-const pointer or non-const reference. The standard library uses references (e.g., swap, advance). Many people, including Bjarne Stroustrup, like the C approach of using pointers.
      • As you mention Effective C++, it also cautions against the design problems of having a concrete base class, teaching that base classes should be abstract. That's not a C++ workaround; it's just good design.
      • A resource (or RAII) class (std::string, std::fstream, std::vector, smart pointers, etc.) holds a resource that naive code would manage explicitly, so that you don't run into issues because almost all classes only use pointers where copying the pointers is just fine.

      It's true that using C++ has a big learning curve. When you're a reasonable way up that curve, it's often a much more productive language because it's so much more capable of expressing the design directly in the language. That said, I use many languages, depending on the context. I just don't like people avoiding a programming language because of misunderstandings.

    3. Re:Refutation by GooberToo · · Score: 1

      I would like to thank you for writing answers to issues which simply do not exist. I'm sure some may have been willing to buy into his bullshit. It would appear he's been reading the horribly inaccurate and terribly misleading C++ FQA, which is full of bullshit and hand waving. Not to mention, it actively instructs coders to do things the worst possible way; and then espouses that's why C++ is broken. Which, of course, completely ignore the fact that no language can protect one from idiots.

      I see in his follow up his response is, "oh...well... you didn't buy into my bullshit, so I'll have to do some more hand waving to see if I can yet confusing you into believing my bullshit."

      Thanks.

  74. Re:Virtual functions as mentioned in the link... by GooberToo · · Score: 1

    I will repeat the assertion that the only thing STL brings to the table is generic containers.

    Wrong. It brings generic containers and algorithms. But saying it like that somehow diminishes what it brings to the party. Its a lot like saying, "Pah - using doctors can ONLY save your life. Its no big deal."

    As for reduced line count, the GP post is absolutely correct - assuming you're not counting the generated code associated with STL's template instantiation. Which frankly, is generally not considered for line counts. So if you have many different data types which must otherwise be tracked, in C, you have many different implementations of hand crafted code to handle all these different types - generally all doing the same thing. Or, you've generalized it (void * plus a magic/type in a structure) and thrown away the limited type safety provided by C. Or, you can replace all that, while adding additional type safety with fewer lines of code. Additionally, the STL implementation is far more likely to be much, much faster, not to mention bug free; especially for more complex containers and algorithms.

  75. Re: GCC Moving To Use C++ Instead of C by source2net · · Score: 1

    "Still undecided is what subset of C++ to use".., they need to identify their core needs to answer this question. I would really like to see what they actually come up with. This might be good news..., i hope.

  76. New name? by Anonymous Coward · · Score: 0

    So, now it's GC++C++?

  77. Limiting your developer pool by Anonymous Coward · · Score: 0

    Currently, to understand all of gcc you need to understand C. If parts of it start to be written in C++, then the developers who only know C will be unable to understand all of gcc. So you'll be limiting the pool of developers, not increasing it.

    Imagine a C developer debugging or developing and tracing through a call sequence only to discover that suddenly the code in question is C++. Suddenly their skills aren't enough.

    If C++ is used only for the code that's used to implement C++ itself, the above issue is not so bad. But I wonder how the purity of the non-C++ parts of the collective will be assured. It sounds like a tricky code management problem.

    I'd also be interested to see a study comparing the bug rate and bug fix rate for C++ vs C. My personal observations are that both are better with a simple language rather than a very complex one.

    Frankly, this decision seems like a very bad one, and one where the impact will be felt very gradually, with increasing weight over time.