Slashdot Mirror


GCC Switches From C to C++

According to a post on the GNU Compiler Collection list, GCC is now built as a C++ program by default. This is the fruition of much effort, and the goal now is to clean up the GCC internals that are reportedly pretty type-unsafe by rewriting them using C++ classes and templates.

406 comments

  1. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0, Offtopic

    This is the first I've heard of anything like this. Did I miss something? Is GCC now GPLv3, and does that mean you can't use it to build non-GPL programs?

  2. Re:too bad GCC is not relevant anymore thanks to L by DeathToBill · · Score: 5, Informative

    Irrelevant? Not quite. For your particular use, maybe. But most Linux distros are still built using GCC, and most embedded platforms provide a GCC-based toolchain. So if, by 'irrelevant', you actually mean, 'the compiler with the most-often executed output code on earth', then yes, I guess you're right.

    --
    Slashdot - News for Nerds, Stuff that Matters, in ISO-8859-1 Has just realised that beta makes this signature redundant
  3. Major *nix app using C++ by PhrostyMcByte · · Score: 3, Funny

    I'll go get my cats-and-dogs umbrella.

    1. Re:Major *nix app using C++ by Joce640k · · Score: 1

      Linus must be screaming inside.

      --
      No sig today...
    2. Re:Major *nix app using C++ by smittyoneeach · · Score: 1

      Only if the C++ cooties creep into the kernel.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    3. Re:Major *nix app using C++ by Nethemas+the+Great · · Score: 3, Funny

      I don't know. He's been doing some pretty crazy things lately like versioning the kernel as something other than v2.6.x..

      --
      Two of my imaginary friends reproduced once ... with negative results.
    4. Re:Major *nix app using C++ by formfeed · · Score: 5, Funny

      Linus must be screaming inside.

      Linus never allows his screaming to stay on the inside

    5. Re:Major *nix app using C++ by hpa · · Score: 2

      Linus doesn't scream. He obliterates with sarcasm.

  4. This is a good thing... by Red4man · · Score: 2

    .. and will lead to an even more reliable compiler toolchain.

    --
    Sock Puppets: damn_registrars=pudge_confirmer=jimmy_slimmy=raiigunner=cml4524=a_klavan=red4men=ronpaulisanidiot
  5. Re:too bad GCC is not relevant anymore thanks to L by Nursie · · Score: 4, Informative

    No, no it does not mean anything of the sort.

  6. Type unsafe... by Anonymous Coward · · Score: 1

    GCC internals are lisp-written-as-C. *cough*

    1. Re:Type unsafe... by Carewolf · · Score: 2

      Yeah, that always freaks me out. GCC backends atleast are configured using LISP wrapped in C. I hope this is one of the things they clean-up, though, it won't be straight forward. LISP is quite powerful and fast as a machine language, it just happens to be unparsable by humans.

    2. Re:Type unsafe... by Anonymous Coward · · Score: 1

      ((Yes ((LISP( is (quite) unparsable by) humans.))))

    3. Re:Type unsafe... by Anonymous Coward · · Score: 2, Interesting

      (not (quite_like (works LISP) you_say))

    4. Re:Type unsafe... by Anonymous Coward · · Score: 1

      At least the instruction descriptions could be fairly easily be converted into valid C++.
      It would take a lot of work, but the basic structure maps fairly well to C++.
      Each instruction is essentially A combination of several properties, each of which could be a field in a class.
      The type would simply become the class.
      In the simplest case the operand requirements would be a string variable just like they are now, and the predicates a list of function pointers.
      More likely these would in turn also be converted into classes.
      The actual production rules are already just C functions wrapped in a lisp like format, so no problems there.
      The attributes can be again a list of strings.
      There are more features, but all in all I don't see any great difficulty on that front.

      The far harder part would seem to me, to rewrite the instruction scheduler, combiner and matcher to work on these objects instead of on whatever representation they use at the moment.

      Probably even harder is the actual pipeline description.
      Converting that into C++ would probably make it far to verbose to be useful, and I think it is mostly fine as is, although, it could definitely add some more support for certain features (or more accurately lack of features).

    5. Re:Type unsafe... by Anonymous Coward · · Score: 0

      It is still better than XML in my book. Data/database/code all in one. Who needs strong typing.

    6. Re:Type unsafe... by Anonymous Coward · · Score: 0

      (by (is (LISP unparsable (quite)) humans) Yes)

    7. Re:Type unsafe... by iluvcapra · · Score: 1

      (decl (wars) (not (make one great))

      --
      Don't blame me, I voted for Baltar.
    8. Re:Type unsafe... by jonadab · · Score: 3, Insightful

      > LISP is quite powerful and fast as a machine
      > language, it just happens to be unparsable by humans.

      What on earth are you talking about? Lisp is extremely trivial to parse. Lisp barely even has syntax.

      Now, keeping track of Lisp program flow in your head, that can be a bit tricky and can lead to some substantial maintainability issues, especially when some hotshot programmer starts throwing lambda functions around like there's no tomorrow (or, worse, continuations).

      But parsing? Parsing Lisp is dead simple. You could train an elementary education major to do it.

      --
      Cut that out, or I will ship you to Norilsk in a box.
    9. Re:Type unsafe... by Darinbob · · Score: 2

      What, who can't parse Lisp? It's incredibly simple. People don't like it because they're not used to it is all.

    10. Re:Type unsafe... by rve · · Score: 1

      Yeah, who wouldn't want to write a syntax tree by hand? Who needs a parser? The programmer is your parser, such is the power of Lisp!

    11. Re:Type unsafe... by sonamchauhan · · Score: 1

      (cons (first (not (agree-with (you me)))) (last (parse-with computer lisp) elegance)

  7. Incoming Torvalds' post by Anonymous Coward · · Score: 1

    Hey folks, bring up your umbrellas, Torvalds has something to say about this.

    1. Re:Incoming Torvalds' post by Anonymous Coward · · Score: 2, Funny

      umbrellas? I'm getting some popcorn and a comfortable chair. this is going to be epic.

    2. Re:Incoming Torvalds' post by Anonymous Coward · · Score: 0

      this is going to be epic.

      This is why the umbrellas are for, if the epicness is delivered in Microsoft-style.

  8. Re:too bad GCC is not relevant anymore thanks to L by keltor · · Score: 2

    While the GPLv3 was the reason Apple suddenly invested in clang (which just happens to ride on llvm), it has little effect on any companies that do what they should do.

  9. Next steps by Anonymous Coward · · Score: 1, Funny

    The next step is switch from C++ to Java.
    Then, finally, switch to PHP as the default language to build GCC.

    1. Re:Next steps by xTantrum · · Score: 3

      I'm a hot chick at college studying computer science using Python. insensitive clod!

      --
      $action = empty(PHP) ? backToC() : unset(PHP) ; "when the concrete cases are understood, the abstractions are readily
    2. Re:Next steps by Karzz1 · · Score: 1

      1). Posting on Slashdot
      2). Hot chick at college
      3). Studying computer science
      4). Using Python

      Which one of these things don't belong? :D

      --
      Beware of he who would deny you access to information, for in his heart he dreams himself your master.
    3. Re:Next steps by iluvcapra · · Score: 1

      I see a reddit anti-misogyny thread in our future.

      --
      Don't blame me, I voted for Baltar.
    4. Re:Next steps by chronokitsune3233 · · Score: 0

      #1 of course. Everybody knows that chicks can't post on Slashdot, especially after being boiled alive. Mmm... Eggs...

      --
      I have been a captive in America my entire life. Everybody and everything uses customary units instead of metric.
    5. Re:Next steps by schroedingers_hat · · Score: 1

      They're all fine. The closest one to not fitting in my book is the python bit, but even that doesn't matter. Computer science isn't about actual physical computers, python has almost all the shiny functional language features cs types care about, and all of the well reasoned and coherent criticism I've seen of the whole whitespace thing apply more to large scale/collaborative projects than smaller things (also, enforced whitespace sounds like a boon for marking anything).
      Less time you spend learning/dealing with the language, more time you can spend on the actual meat of the subject.
      This being said, I think anyone who is planning on going near a real computer should do some architecture stuff and learn with assembly at some point, too.

    6. Re:Next steps by Anonymous Coward · · Score: 0

      1, because it's true.

  10. Re:too bad GCC is not relevant anymore thanks to L by Carewolf · · Score: 1

    For a compiler? What does a distribution license have to do with a compiler?

    You seem to be treating the GPL like cuties.. Who does believes in GPL cuties? Apple, FreeBSD, 6 year olds, anybody else?

  11. RTFA by Anonymous Coward · · Score: 0

    GCC needs to be compiled by a C++ compiler.

    Since the GCC project also have a C++ compiler, I don't see the big deal.

    1. Re:RTFA by Joce640k · · Score: 1

      Listen more carefully. All the C diehards are screaming in rage.

      --
      No sig today...
    2. Re:RTFA by MichaelJ · · Score: 2
      Maybe not a big deal on a Linux system with an older G++ already installed, but this could be a serious issue for bootstrapping GCC on non-Linux platforms. Where you might have only needed the native C compiler before, now you will need the native C++ compiler, which may be an expensive product.

      Unless they're going to make it a multi-step bootstrap where the first pass is only C code. I highly doubt that.

      --

      Michael J.
      Root, God, what is difference?
    3. Re:RTFA by JCCyC · · Score: 1

      Yo dawg, I head you like C++ compilers, so I compiled your C++ compiler with a C++ compiler!

    4. Re:RTFA by maxwell+demon · · Score: 1

      You could also get an earlier g++ as C++ compiler. I guess they don't allow C++11 features yet.

      Alternatively you can cross-compile it from a Linux system.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    5. Re:RTFA by bluefoxlucid · · Score: 1

      Yeah. I'm not a fan of C++, though the compiler spends so little time running that this shouldn't pose much of a problem with bloat and clunk. On the other hand, loading C++ stuff is an abomination that takes eternity due to massive mangling (a problem Michael Meeks has spent a lot of time trying to marginalize with Bdirect linking, faster hash algorithms, etc), and the compiler gets run repeatedly.

      Though I guess the guy that tried to convince me C++ is a strict superset of C and that all C will compile as C++ can now enjoy his front page article about how he was wrong.

    6. Re:RTFA by nebosuke · · Score: 3, Informative

      Bootstrapping on another platform is done as follows:

      1. Write gcc backend to output code for target platform.
      2. Cross-compile gcc for target platform using an already-supported-platform and the newly written backend.
      3. Transfer resulting binaries to target platform
      4. profit!

      Note that at no point does the target platform need some other way to compile gcc independently in order for the port to happen.

    7. Re:RTFA by Anonymous Coward · · Score: 0

      > though the compiler spends so little time running

      I wouldn't assume everyone is writing simple apps. Many of us have million line codebases that take hours to do a full build

    8. Re:RTFA by Joce640k · · Score: 3, Interesting

      Yeah. I'm not a fan of C++, though the compiler spends so little time running that this shouldn't pose much of a problem with bloat and clunk. On the other hand, loading C++ stuff is an abomination that takes eternity due to massive mangling (a problem Michael Meeks has spent a lot of time trying to marginalize with Bdirect linking, faster hash algorithms, etc), and the compiler gets run repeatedly.

      I'm not sure mangling is really as much of a problem people make it out to be. It *did* cause problems trying to mix binaries from different compilers but I don't think it was ever really a performance problem. If linking is slower it's because the programs are larger.

      OTOH name mangling is a massive benefit to programmers. Writing big programs is a huge pain in the butt if every single function/variable has to have a unique name. Namespaces are one of the reasons C++ programs scale so much better then C programs.

      --
      No sig today...
    9. Re:RTFA by Darinbob · · Score: 2

      If they use the Smarter-C-than-C parts of C++ it's fine. Just don't start going overboard with modern C++ style, bloatware with templates and generics, autopointers, overloaded operators and functions, etc, then it's great. Use it as C with better type checking and easier modularization and the C diehards will approve.

    10. Re:RTFA by Darinbob · · Score: 1

      Mangling is mostly a pain to debugging. Too many tools, even GNU tools, have problems demangling stuff to give you human readable diagnostics.

      Actually I think anonymous namespaces don't help much because the semantics means those names are out there at link time, slowing down an already slow link. Static functions remain hidden from the linker even though the C++ purists won't like it.

    11. Re:RTFA by Darinbob · · Score: 1

      Yes but now you've sort of got an extra step. It used to be you could use a native compiler already existing on the target machine to compile gcc on that machine. Now you may need a cross compiler to do the same thing.

      Maybe it doesn't matter as much now as just about everything's x86 now and if you need a special gcc build it's almost always for an embedded cross compiler. As opposed to a couple decades ago when it was more common to want to replace an expensive or slow native compiler on a desktop workstation.

    12. Re:RTFA by aled · · Score: 1

      If they use the Smarter-C-than-C parts of C++ it's fine. Just don't start going overboard with modern C++ style, bloatware with templates and generics, autopointers, overloaded operators and functions, etc, then it's great. Use it as C with better type checking and easier modularization and the C diehards will approve.

      Amen to that.

      --

      "I think this line is mostly filler"
    13. Re:RTFA by Deorus · · Score: 0

      Actually I think anonymous namespaces don't help much because the semantics means those names are out there at link time, slowing down an already slow link. Static functions remain hidden from the linker even though the C++ purists won't like it.

      There is absolutely no reason for anonymous namespaces to be implemented any differently from static functions and objects. The reason why some people discouraged the use of static objects and functions in C++ to make stuff only visible to its own translation unit is because C++03 deprecated them, but C++11 has un-deprecated it again. Still, the choice between static or anonymous namespaces should have no impact on the final code (personally I choose static for esthetic reasons).

    14. Re:RTFA by bluefoxlucid · · Score: 2

      The problem with mangling is C gives you a symbol like "strcpy", which you might compare for the 50,000 links that have to be made during program load, and have to perform 300,000 character comparisons.

      In C++ you get _NSstd__IOSTREAM__55STRING_OPEREQ__STRING__STRING__CHARX__ or some crazy thing. You wind up with 100, 150, 250 character long function names for class foo member 'int bar(int, &int)'. To make matters worse, the above hypothetical was ridiculous: you won't do 300,000 character comparisons because there are only about 20 str* functions, you'll do 60 comparisons (20x3) plus around 50,000 more because of all these functions that don't start with 's' (though there will be a couple thousand that do, but don't start with 'st', adding a few thousand more comparisons). In C++, though, things aren't so friendly...

      In C++, you actually wind up comparing, as per our approximated example, _NSstd__ for EVERYTHING in the std namespace. That's 8 character comparisons per symbol (function, overloaded operator, variable, class, class member, etc) in the std namespace--everything in the STL. That once for EVERY symbol in the STL. EVERYTHING under the IOSTREAM class has to compare _NSstd__IOSTREAM__, so each one of those totals 18 character comparisons per member of the IOSTREAM class. That means just to load IOSTREAM you definitely have to do (members_of_iostream^2 * 18 / 2) character comparisons. In the real world, you can do hundreds of thousands or even millions of character comparisons just to load one C++ class member.

      It used to take about 14 seconds to load OpenOffice.org on a given piece of hardware. Michael Meeks made that about 1.7 seconds by direct binary linking (i.e. telling the linker that a given symbol was in a given library), avoiding 95% of the character comparisons. It got down to somewhere between 2.5 and 3.5 seconds with just Meeks' PT_GNU_HASH non-standard ELF extension, which adds sorted bucket hashes to the symbol tables to bypass most of the work--it worked so well, in fact, that after publicly discussing the patch on the glibc mailing list as Meeks repeatedly submitted new versions, Ulrich Drepper waited a month and then put his name at the top of the patch and claimed he wrote it (on the same mailing list!).

      Meeks had white papers written about this shit. He showed how long it takes C programs to link versus similar C++ programs, explained why, then set out to mitigate the stupidity caused simply by using C++. Current gcc toolchains produce PT_GNU_HASH headers (precomputed ELF hashes) and sort the symbol tables to match the ordering of the hash tables, allowing glibc to basically walk through the binary in a straight line. This eliminates the CPU overhead of computing hash values (never mind character comparisons, we're doing a ton of math) and puts everything in a straight line so PREFETCH instructions and just built-in automated CPU prefetching can reasonably eliminate CPU cache misses--which makes things REALLY fucking fast. Loading a C++ program on Linux is now roughly half as fast as loading an architecturally equivalent C program, which is an improvement over the 10x longer it used to take to load C++ programs.

      You can see a bunch of shit at http://lwn.net/Articles/192624/ for the executive summary. Sorry the writing's so poor; I need to not write technical column articles like I write slashdot posts.

  12. Re:too bad GCC is not relevant anymore thanks to L by shic · · Score: 1

    Does LLVM have features for coverage analysis to compare with GCOV?

  13. Classes/Templates are not a magic bullet ... by perpenso · · Score: 2

    Given a collection of developers that write difficult to understand, difficult to maintain and sloppy type unsafe code, going to C++ may not help. The previous problems are problems with the developers not the language. C++ just enables such developers to write even worse code. Hopefully they are also introducing new coding style guidelines, and are willing to enforce such guidelines. If so I'd be more optimistic.

    I'd also be more optimistic if by using classes and templates they were really referring to using STL, not writing their own.

    Or maybe they just want to use C++ style comments and won't really use classes and templates much. :-)

    1. Re:Classes/Templates are not a magic bullet ... by gbjbaanb · · Score: 4, Insightful

      Bad code is bad code, and you can write it in any language, yes, even visual basic.net.

      So the point is not so much "how useless are those lousy GCC devs who will write crappy code", but "how good are those GCC devs now they have a more powerful tool in their hands".

      I'd hope they start to discover the STL too, and use the standard containers at the very least - no need to use custom ones unless you either continue to use the existing C-based ones, or you have some very specific performance issues that you absolutely cannot fix any other way (and generally, you don't have this problem with the STL)

      Now, sure, I hope they don't discover cool new features like STL algorithms and start to litter the code with lamba-d functors.

    2. Re:Classes/Templates are not a magic bullet ... by Marillion · · Score: 3, Informative

      The Linux Kernel used the C++ compiler for a while. I believe it was during the 0.99.x era. The goal was to improve the code quality by leveraging C++ compiler features like function name mangling while only using C language features. This, however, looks like they want to use a limited set of C++ language features that would be very handy for experienced C programmers.

      --
      This is a boring sig
    3. Re:Classes/Templates are not a magic bullet ... by serviscope_minor · · Score: 5, Informative

      Given a collection of developers that write difficult to understand, difficult to maintain and sloppy type unsafe code, going to C++ may not help.

      It is very difficult to write easy to understand, type-safe, code in C.

      The reason being that C requires so much micro-management that you end up with the code for that mixed in with the actual interesting algorithms. C++ basically makes the compiler do an awful lot of what you have to do in C anyway and does it for you automatically while keeping the details neatly out of the way.

      It's also very hard to write type safe code properly in C. Just look at the classic example of the unsafe qsort versus the safer and faster std::sort.

      I'd also be more optimistic if by using classes and templates they were really referring to using STL, not writing their own.

      What on earth is wrong with writing your own classes and templates? They almost certainly already have a healthy collection of structs with function pointers and macros (linux certainly does have poor reimplementations of half of C++ using macros). These are best replaced with classes and templates on the whole.

      That's the point. C++ formalises what everyone was doing in C anyway, making it much more uniform, easier to read, shorter and therefore much less prone to bugs.

      --
      SJW n. One who posts facts.
    4. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      I find that jerks who bitch the most are often the worst at writing code, sorry just sayin. Big ego = ass hat to work with and awful at writing code. C# might work out better for ya.

    5. Re:Classes/Templates are not a magic bullet ... by ArhcAngel · · Score: 4, Funny

      I find that jerks who bitch the most are often the worst at writing code, sorry just sayin. Big ego = ass hat to work with and awful at writing code. C# might work out better for ya.

      Shouldn't that be:
      Big ego == ass hat

      --
      "A person is smart. People are dumb, panicky dangerous animals and you know it." - K
    6. Re:Classes/Templates are not a magic bullet ... by Surt · · Score: 4, Funny

      No, it's definitely an assignment.

      --
      "Who is the Journal of Quantum Physics going to believe?" --Stephen Hawking
    7. Re:Classes/Templates are not a magic bullet ... by Joce640k · · Score: 1

      going to C++ may not help.

      I dunno. I don't see what business non-C++ programmers have working on a C++ compiler. One of the problems might be that they're still using malloc() and strdup().

      --
      No sig today...
    8. Re:Classes/Templates are not a magic bullet ... by Rei · · Score: 2

      There are some cases where lambda-d functions improve clarity. For example, lambdas make for very clear, concise threading of simple tasks using the new C++11 threading operations.

      Really, many of the new features play so beautifully together. For example, you can write a simple packet reader/parser which:

      * Loops indefinitely
      * Waits until data can be read
      * Spawns the processing of that data in its own thread and resumes holding and processing packets, while in the spawned thread:
      * Proper type of packet is determined
      * Appropriate packet object is created
      * Packet object processed
      * Packet object deallocated

      Using code one-liners like:

      while (true) { auto PacketData=ReadPacket(); thread([]{ MyPacketFactory(PacketData)->RunPacket();}).detach(); }

      or

      while (true) { thread([](auto PacketData){ MyPacketFactory(PacketData)->RunPacket();}, ReadPacket()).detach(); }

      Now, it's stylistically better to spread it out over a couple lines, and the above assumes that you're "using" std, have written your packet factory and socket reader, etc. However, it gives you an idea of how powerful the new features are. In normal code I'd probably write something like:


      while (true)
      {
            std::string PacketData(ReadPacket());
            std::thread([]{ MyPacketFactory(PacketData)->RunPacket();}).detach();
      }

      Again, to reiterate, this is just from memory; I've not tried to compile these.

      --
      We're practicing our labials.
    9. Re:Classes/Templates are not a magic bullet ... by TheGratefulNet · · Score: 0

      when I first experienced C++ and the trash that most developers put out, I started calling c++ 'write-only code'. you can write it but you can't ever read it back, years later.

      I still stand by some of that. almost any task can be written clearer in c than c++. c++ does not give much, in reality, for 99% of what people tend to use a language for.

      having spent a few decades on c and c++, I still prefer c and avoid c++ as much as I can. over time, it just has not won me over.

      I don't write 'university code' though; and I'm not out to impress a professor or win 'elegance awards'. I write simple code that runs and is easy to support. the only time I'll choose c++ is if a project is already written in it, and heavily invested in it. any new project of mine will not be c++ based.

      been coding since I was in my teens and I'm in my 50's now. years of experience has not shown c++ to be any benefit in any real sense.

      --

      --
      "It is now safe to switch off your computer."
    10. Re:Classes/Templates are not a magic bullet ... by cras · · Score: 1

      It's also very hard to write type safe code properly in C. Just look at the classic example of the unsafe qsort versus the safer and faster std::sort.

      You can do all kinds of nifty stuff with macros and gcc/clang extensions to provide type safety to C. Yeah, if you don't already have a library for that it can be a bit difficult to write one (or find one you like). But once you have the library it's very easy to write (mostly) type safe code with C. For example I have a type safe array_sort() in C.

    11. Re:Classes/Templates are not a magic bullet ... by serviscope_minor · · Score: 5, Insightful

      You can do all kinds of nifty stuff with macros and gcc/clang extensions to provide type safety to C

      Yes, I know.

      You can write a GENERATE_SORT(Type, Comparator) macro which generates a sort function to work on an array of Type, using the specified comparator, and has no name collisions and is type safe using liberal amounts of ## and so on.

      The point is not that you can't do them in C (you can), but the methods for doing it are ad-hoc. By moving the functionality into the compiler, C++ provides a regularity of syntax for such things that C lacks.

      --
      SJW n. One who posts facts.
    12. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      I find that jerks who bitch the most are often the worst at writing code, sorry just sayin. Big ego = ass hat to work with and awful at writing code. C# might work out better for ya.

      You mean better for yourself. Using your own criteria and the fact that you seem to be bitching more than anyone else.

    13. Re:Classes/Templates are not a magic bullet ... by serviscope_minor · · Score: 5, Insightful

      I don't write 'university code' though; and I'm not out to impress a professor or win 'elegance awards'.

      I think the enormous chip on your shoulder might be obscuring your view of C++.

      --
      SJW n. One who posts facts.
    14. Re:Classes/Templates are not a magic bullet ... by cras · · Score: 1

      Well, that kind of GENERATE_SORT() seems very ad-hoc way to do it and very specific to a sort.. My method looks more like this (dynamically growing type safe arrays):

      #include "array.h"
      int foobar_cmp(const struct foobar *f1, const struct foobar *f2); ..
      ARRAY_DEFINE(foobars, struct foobar);
      struct foobar f; ..
      array_init(&foobars, 16);
      array_append(&foobars, &f); ..
      array_sort(&foobars, foobar_cmp);

      I don't think that's much different (or more difficult) from how you'd do it with C++ templates. Of course implementing array.h is easier with C++.

    15. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      STL algorithms are not exactly "new".

    16. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      You're missing the point again. Why not stop replying and leave the thread? This isn't a contest to find C hacks to provide C++ built-in features, the point is to avoid that kind of shitty coding in the first place.

    17. Re:Classes/Templates are not a magic bullet ... by serviscope_minor · · Score: 1

      wouldn't it be better to do:
      ARRAY_DEFINE(foobars, foobar); ...

      array_init_foobar(&foobars, 16); ...

      etc

      That way, you can have arrays if ints, floats, foobars, etc without name collisions pn array_init, etc.

      --
      SJW n. One who posts facts.
    18. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      I don't write 'university code' though; and I'm not out to impress a professor or win 'elegance awards'. I write simple code that runs and is easy to support.

      And so do the people writing C++. The only difference is that they aren't idiots calling code better than theirs "code that tries to win elegance awards".

    19. Re:Classes/Templates are not a magic bullet ... by gbjbaanb · · Score: 1

      ah, don;t get me wrong - inline lambdas for little functions are great, its just a warning not to find this cool new feature and start using them everywhere.

      They can make debugging harder and code less readable, but for little functions they're great.

    20. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      So the point is not so much "how useless are those lousy GCC devs who will write crappy code", but "how good are those GCC devs now they have a more powerful tool in their hands".

      Actually it sounds like they've needed to do a fair bit of rewriting effort to port things from C to C++. Don't know about you, but I find that if I port code from one language to another, this invariably forces me to clean up "icky" constructs to something cleaner.

    21. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      And yet GP is still modded +3.

      Captcha: madhouse

    22. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      It's hard to avoid C++ if you need to use a GUI framework. There're alternatives, but they tend to suck. It is unfortunate that C++ took hold in industry, - this language is the Holy Bible of poor design.

    23. Re:Classes/Templates are not a magic bullet ... by bytesex · · Score: 0

      Unnecessary change is unnecessary. But it is one of the more vexing characteristics of open source projects. There are many problems with C++, but one of them is that, in general, programs benefit from simplicity. I would trust a C compiler written in C much more to generate bug-free instructions than I would trust a C compiler (or any compiler for that matter) written in C++. Not because of the 'write the compiler in the language itself'-principle but because of the closeness of C to assembler; it's easier to see where the code is going.

      Oh well, it was good while it lasted, I suppose.

      --
      Religion is what happens when nature strikes and groupthink goes wrong.
    24. Re:Classes/Templates are not a magic bullet ... by philfr · · Score: 3

      I could be wrong, but I doubt the Linux kernel ever used anything C++ related, given the strong opinion Linus has about the language

    25. Re:Classes/Templates are not a magic bullet ... by maxwell+demon · · Score: 1

      Yes, and then, when the developer moves on to somewhere else, all the stuff he learned about this clever system is useless because the other company has developed a different clever system. On the other hand, the C++ developer has to learn the stuff once and can expect to be able to use that knowledge at his next job as well because it is part of the standard.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    26. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      If being close to assembly makes it easier to see where code is going, maybe they should just write it in assembly then! ;)

    27. Re:Classes/Templates are not a magic bullet ... by shutdown+-p+now · · Score: 1

      You need to specify the capture when using locals from inside the lambda, i.e.:

      std::thread([PacketData]{ MyPacketFactory(PacketData)->RunPacket();}).detach();

      or let it implicitly capture everything that's referenced:

      std::thread([=]{ MyPacketFactory(PacketData)->RunPacket();}).detach();

    28. Re:Classes/Templates are not a magic bullet ... by Zan+Lynx · · Score: 2

      If you look at the way the Linux kernel uses macros combined with GCC extensions like typeof(x), it is obvious that they are actually writing templates. And many of their struct definitions reproduce inheritance and virtual method calls.

      You could look at it as writing C++ code disguised as C.

    29. Re:Classes/Templates are not a magic bullet ... by Darinbob · · Score: 0

      No, I hope they don't discover STL containers. That will bloat up the size of the compiler because those containers are templated generics, and the compiler/linker today essentially compile those as duplicated code. STL code is also too generic and optimized for a generic case; they're not optimized for specific cases (especially the algorithms).

      Now I do like a good container library, but C++ as a static language isn't set up to use this idea well. Smalltalk does wonders with it because it can reuse a class without making a complete duplicate of the class. Generics are great for rapid prototyping if you don't care how much big or slow it is, but once the prototype is done then you should logically want to use something more efficient.

      The biggest problem here I think stems from the C++ style of using objects directly instead of type-checked pointers to objects (value-based instead of pointer-based). Ie, a linked list of objects using STL style generics will have difficulty sharing code between the two instantiations (bloat) and will also have to deal with copy constructors getting objects into and out of the container (bloat and speed). But you can have a template that enforces type correctness of pointers to objects that then uses a container of void* for example, code gets shared, objects don't get copied, and it's very efficient. Yes you're back to having to worrying about who owns objects but really that's a problem that can be solved without resorting to STL style.

    30. Re:Classes/Templates are not a magic bullet ... by perpenso · · Score: 1

      One can do simple in C++. Some programs can be simpler in C++ than C. The problem is that programmers sometimes choose to use some advanced feature because they can, not because it is the right tool for the task at hand.

    31. Re:Classes/Templates are not a magic bullet ... by Darinbob · · Score: 1

      The problem very often is that when you use qsort you call a precompiled library, only one copy of it exists, but when you use std::sort you may end up with many copies of the sort algorithm in memory. Not only is this a a lot of extra memory it also hurts run time because more memory means less locality of reference for caches and more likelihood of having to swap.

      In this case C++ hides too much of the details; if you want to write efficient code then you do not want details to be hidden. When you just want a rapid prototype then you don't need to worry about details. C++ can work well with both styles, however when you want efficiency you usually have to give up the ease of programming that high level generics and generic algorithms gives you.

      You CAN have type safe code with qsort. Either put a function wrapper around all uses of qsort that verifies all parameters are of the right type, or automatic this with a template wrapper around it. Then the sort routine itself remains efficient and precompiled in a library while still giving you the type safety that you want. It's only slightly more work than just using std::sort.

      And using qsort as a "classic example" seems fishy. This is not a common source of errors and of all the places where type checking can mess up in C this is probably the least of the worries.

    32. Re:Classes/Templates are not a magic bullet ... by gbjbaanb · · Score: 1

      erm, I think you need to learn more about it. You're trying to apply C semantics to C++ programs assuming that the C style is the only way to achieve performance and efficiency. Its not the case.

      Most compilers will happily optimise and remove a lot of redundant code, things like RVO (for an example) shows how you can return a full object from a function yet no copying of that object takes place - the compiler optimises it so the returned object occupies the destination space directly.

      Even for template code that is instantiated for different types, this isn't much of an issue. Strongly typed code is a tradeoff worth having, code is tiny anyway compared to data.

      Now there are cases where you do need a collection of pointers to heap-based objects. You can still have such a thing, even using the STL - a list of void* is still valid, but you can also have a list of shared_ptr types, so you get everything you want (no bloat, no object copy) and everything I think is good (type safety and object semantics) at the same time.

      There's also C++ move semantics to in the new C++11 standard. Even Microsoft supports that :)

    33. Re:Classes/Templates are not a magic bullet ... by Urkki · · Score: 3, Insightful

      For you, I suggest two-pronged approach to C++. First of all you have libraries and frameworks. They take full advantage of C++ features, but hide them. Then you have the actual application code that uses these libraries, and is much simpler, ideally readable by somebody who only knows Java or C#.

      The difference to doing the same in C is, in C you'll use macros and have poor type safety, ugly-looking code and get obscure macro related errors when when you put bad stuff as macro arguments.

      In short, the trick with C++ is, you don't use most of the features, unless you really have to. Note that you can write your current C code as C++ code, except use whatever subset of C++ features you think will make your C-like code better, and only when it actually makes it better. Limiting yourself to pure C is, IMNSHO, just stupid, unless you're coding for a small embedded system and don't want to include C++ runtime in it.

    34. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      Bad code is bad code, and you can write it in any language, yes, even visual basic.net.

      haha, point me to ONE piece of bad code written in VB.net :P

    35. Re:Classes/Templates are not a magic bullet ... by cras · · Score: 1

      I'm not sure what you mean. It's possible to have arrays of ints, floats and everything. Looks to me like your idea would assume that array works only on structs? Anyway here's the implementation: http://hg.dovecot.org/dovecot-2.1/file/tip/src/lib/array.h

    36. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      My favorite moment in working with customer code came about 10 years ago. The company wanted to enforce encapsulation in their coding standard but had these two gems sitting in a master header file...

      #define private public
      #define protected public

      I really tried to stifle my laughter.

    37. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      C++ and C have different philosophy. Obviously one is strongly typed and the other is weak typed. But this implies not just about that 'C++ is more safe', but exactly two opposite direction to abstraction. In a C++ programmer's view, the operations should be generic while the data should be distinguished. (Here I mean operations and data are some kind of conjugate). For an adequate C programmer who doesn't intend to mimic the 'more modern and safer' style, will see everything as a limited range integer/bit string associated with a limited range integer called address. The types are just the size/offset information communicating with compilers.
      How those integer/bit string are interpreted/manipulated depends on the operations. Yeah, C is typed but still flowing blood from the antiquity typeless origin. In addition, C++ programs do much more effort on communicating with compilers rather than directly the target machine.

    38. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      C++ and C have different philosophy. Obviously one is strongly typed and the other is weak typed. But this implies not just about that 'C++ is more safe', but exactly two opposite direction to abstraction. In a C++ programmer's view, the operations should be generic while the data should be distinguished. (Here I mean operations and data are some kind of conjugate). For an adequate C programmer who doesn't intend to mimic the 'more modern and safer' style, will see everything as a limited range integer/bit string associated with a limited range integer called address. The types are just the size/offset information communicating with compilers.
      How those integer/bit string are interpreted/manipulated depends on the operations. Yeah, C is typed but still flowing blood from the antiquity typeless origin. In addition, C++ programs do much more effort on communicating with compilers rather than directly the target machine.

      I am Anonymous, I don't mean gcc's code is good. instead I hate it.
      What I mean is C is not inherently leading to bad code.

    39. Re:Classes/Templates are not a magic bullet ... by Marillion · · Score: 1

      back in the day ...

      They used the C++ compiler to compile Linux kernel written because of Name Mangling. Code that tried to pass incorrect parameters got link errors.

      Now get off my lawn you whippersnappers.

      --
      This is a boring sig
    40. Re:Classes/Templates are not a magic bullet ... by cras · · Score: 1

      Any time you join an existing project you have to learn how to use its libraries, this is no different. Yeah, maybe you'll save a few hours of learning time if some of it is standardized by the base language. If that becomes a real issue with someone you probably shouldn't have hired him/her anyway.

    41. Re:Classes/Templates are not a magic bullet ... by Jonner · · Score: 1

      The Linux Kernel used the C++ compiler for a while. I believe it was during the 0.99.x era. The goal was to improve the code quality by leveraging C++ compiler features like function name mangling while only using C language features. This, however, looks like they want to use a limited set of C++ language features that would be very handy for experienced C programmers.

      You might still be able to compile Linux, as well as other C programs, using a C++ compiler since C++ is still mostly a superset of C. You might even get some benefits of stricter checking.

    42. Re:Classes/Templates are not a magic bullet ... by Deorus · · Score: 1

      You are an idiot and have absolutely no clue about the subject you're attempting to debate.

      No, I hope they don't discover STL containers. That will bloat up the size of the compiler because those containers are templated generics, and the compiler/linker today essentially compile those as duplicated code. STL code is also too generic and optimized for a generic case; they're not optimized for specific cases (especially the algorithms).

      Make up your mind! Either you're against specialized ("duplicated") code or you are against generic (unoptimized) code! You can't be against both at the same time! Also, code-size stopped being a concern a long time ago. Code is usually very small and shared compared to data these days, it no longer makes sense to sacrifice performance for code size on modern systems, and this includes even some embedded systems!

      Now I do like a good container library, but C++ as a static language isn't set up to use this idea well. Smalltalk does wonders with it because it can reuse a class without making a complete duplicate of the class. Generics are great for rapid prototyping if you don't care how much big or slow it is, but once the prototype is done then you should logically want to use something more efficient.

      And that's what C++ does for you. You prototype in the template and the compiler outputs efficient and specialized code! That little speed remark was also quite amusing, you're claiming that a radically dynamic language where no generic code really is optimized for anything is faster than a static language that optimizes everything at compile-time...

      The biggest problem here I think stems from the C++ style of using objects directly instead of type-checked pointers to objects (value-based instead of pointer-based). Ie, a linked list of objects using STL style generics will have difficulty sharing code between the two instantiations (bloat) and will also have to deal with copy constructors getting objects into and out of the container (bloat and speed). But you can have a template that enforces type correctness of pointers to objects that then uses a container of void* for example, code gets shared, objects don't get copied, and it's very efficient. Yes you're back to having to worrying about who owns objects but really that's a problem that can be solved without resorting to STL style.

      Templates of two distinct pointer types usually evaluate to exactly the same code since the pointers are usually represented the same way (though this is not a requirement), and nothing stops you from storing pointers rather than the actual elements in your containers. If you have ownership issues, use smart pointers instead, that's what they exist for, and unlike C, void * and char * are not universal pointers in C++, so never use those (void * is particularly useless in C++).

      There is very little a dynamic language can offer better than C++ in terms of features and absolutely nothing a dynamic language can offer better than C++ in terms of performance or reliability.

    43. Re:Classes/Templates are not a magic bullet ... by Deorus · · Score: 0

      The problem very often is that when you use qsort you call a precompiled library, only one copy of it exists, but when you use std::sort you may end up with many copies of the sort algorithm in memory. Not only is this a a lot of extra memory it also hurts run time because more memory means less locality of reference for caches and more likelihood of having to swap.

      How should I address such a huge amount of bullshit? Let me start:

      First, qsort only works on array types whereas std::sort works on anything that resembles a random input/output iterator;

      Second, in the best case scenario, qsort has to resolve a function pointer and call a function for every comparison whereas std::sort needs neither, which is a monstrous performance loss for qsort;

      Third, in the worst case scenario, qsort still has to resolve a function for every comparison whereas qsort doesn't, which is a huge performance loss for qsort;

      Fourth, for all cases covered by qsort where the comparison is simply a return b > a;, only a single instance of std::sort is needed since only pointers are involved;

      Fifth, if multiple instances of the template bother you more than the performance loss that you'd have with qsort, then providing std::sort with function pointers (as opposed to actual functions or functors) will ensure that only only one instance of the template is generated.

      So, as you can see, std::sort is as bad as qsort in the worst case scenario (if you try really hard) and beats qsort to the ground in every other scenario.

      In this case C++ hides too much of the details; if you want to write efficient code then you do not want details to be hidden. When you just want a rapid prototype then you don't need to worry about details. C++ can work well with both styles, however when you want efficiency you usually have to give up the ease of programming that high level generics and generic algorithms gives you.

      Complete nonsense! Efficiency can be determined by the complexity of the underlying algorithm, which is usually known. For example, you know for a fact that accessing an std::map is O(log n) and that accessing an std::unordered_map is as close as possible to O(1). For further explanations as to why this paragraph is utter nonsense and you should feel incompetent at this point, read what I said about qsort vs std::sort above.

      You CAN have type safe code with qsort. Either put a function wrapper around all uses of qsort that verifies all parameters are of the right type, or automatic this with a template wrapper around it. Then the sort routine itself remains efficient and precompiled in a library while still giving you the type safety that you want. It's only slightly more work than just using std::sort.

      Your ignorance drives you to ridiculousness.

      And using qsort as a "classic example" seems fishy. This is not a common source of errors and of all the places where type checking can mess up in C this is probably the least of the worries.

      What qsort is an example of is a case where C code is A LOT SLOWER than C++ code, and there is no real workaround for this that doesn't involve losing even more functionality (you'd have to implement a non-generic solution in order to match the performance of the C++ generic implementation). Writing wrappers doesn't really solve anything, it only adds bloat to your code, which should be a concern to you were so worried about std::sort's multiple instances, and you aren't allowed to talk about templates because those don't exist in C.

      TLDR: If you are a software engineer, you are an incompetent buffoon.

    44. Re:Classes/Templates are not a magic bullet ... by DuckDodgers · · Score: 1

      Getting things done in C++ is comparatively easy. If you can learn C, you can learn C++.

      On the other hand, maintaining someone else's code in C++ is a crap shoot - just like it is in heavily macro'ed C, just like it is in poorly written Perl. The danger with any overly complex language with tons of features is that the codebase you're looking at could use corners of the language you personally know poorly or not at all.

      The people working on GCC are compiling C++, I'm sure they know every corner of the C++ language as well as Larry Wall knows Perl and Guido van Rossum knows Python. So this is not a problem for them.

      In any domain where getting speed on par with well-written C is not a priority, I would suggest a language with fewer special features.

    45. Re:Classes/Templates are not a magic bullet ... by DuckDodgers · · Score: 1

      Awesome, sorry I don't have any mod points. It reminds me of this: http://steve-yegge.blogspot.com/2010/07/wikileaks-to-leak-5000-open-source-java.html

    46. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      almost any task can be written clearer in c than c++

      I honestly can't tell if you're trolling, or just plain ignorant of the facts - but would you care to share an example to support this preposterous claim? (Bear in mind that to support your claim, it must be a valid C program that is NOT a valid C++ program).

    47. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      I never thought of using an assignment constructor with a default constructor in the same statement...

    48. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      No. It's a syntax error!

    49. Re:Classes/Templates are not a magic bullet ... by Marillion · · Score: 1

      Yes, exactly. That was the rational that was given at the time. It was also expressed that it was temporary.

      --
      This is a boring sig
    50. Re:Classes/Templates are not a magic bullet ... by funky_vibes · · Score: 1

      We're not talking about arbitrary person here, what's been said, is that a good developer will most likely write good code in C.
      Whereas they may be encouraged to write bad code in C++ due to all the bells & whistles.

      Please, STL is a pile of shit, don't recommend it to anyone, ever.
      Boost is even worse.

    51. Re:Classes/Templates are not a magic bullet ... by badkarmadayaccount · · Score: 1

      Real programmers use raw machine code and a refrigerator magnet, yada yada. Go DIAF.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    52. Re:Classes/Templates are not a magic bullet ... by Anonymous Coward · · Score: 0

      There's nothing wrong with using these things in C++. This attitude, that you have to do things the "C++ way" or else, drives people away. Let them use the features they want to use.

  14. In another news... by CuriousKumar · · Score: 1

    .... In a recent report submitted by group of "Expert Consultants", GCC was found to be "too functional" and having "no orientation", and recommended GCC devs to develop some "Class" within and become more "Object Oriented".. ;-)

    1. Re:In another news... by Anonymous Coward · · Score: 0

      Perhaps you could cite something so someone could figure out what the fuck you're talking about.

    2. Re:In another news... by Anonymous Coward · · Score: 0

      Perhaps you could cite something so someone could figure out what the fuck you're talking about.

      Sheldon Cooper is that you??

  15. Re:too bad GCC is not relevant anymore thanks to L by SharpFang · · Score: 3, Insightful

    Don't be so bold in claiming most embedded platforms are something.

    Most embedded platforms use Keil, Assembler and all kinds of various odd proprietary compiler suites that suit their 8-bit and 16-bit nature better. The elitist, narrow though visible of 32-bit ARM is using GCC.

    I assure you your refrigerator temperature thermostat was not programmed in GCC.

    --
    45 5F E1 04 22 CA 29 C4 93 3F 95 05 2B 79 2A B2
  16. Re:too bad GCC is not relevant anymore thanks to L by Bill,+Shooter+of+Bul · · Score: 2

    Gcc still blows the crap out of LLVM in several benchmarks. LLVM is great for many things as well. GCC needed competition to make sure it didn't get stagnent. Some of us still remeber the egcs period of time. Unless corperate entities were modifying the sources of GCC, I'm not sure why it matters.

    --
    Well.. maybe. Or Maybe not. But Definitely not sort of.
  17. Compiler bootstrapping? by Ynot_82 · · Score: 5, Interesting

    How will this affect bootstrapping the GCC on bare systems?

    Been a while since I've delved into LFS or the like, but I'd think GCC being C++ based would seriously complicate things as it's now got more dependencies.

    1. Re:Compiler bootstrapping? by Anonymous Coward · · Score: 2, Insightful

      Not much.

      You can cross-compile all you like.

      If that fails, and you find yourself on a system with only a K&R C compiler, you bootstrap to
      an ANSI C compiler by going to gcc 2.95.n or something like that. Then you use that to get
      to a fairly recent C-based gcc and finally use the resulting C++ compiler to compile the
      final version of gcc.

    2. Re:Compiler bootstrapping? by Anonymous Coward · · Score: 0

      Not much.

      You can cross-compile all you like.

      If that fails, and you find yourself on a system with only a K&R C compiler, you bootstrap to
      an ANSI C compiler by going to gcc 2.95.n or something like that. Then you use that to get
      to a fairly recent C-based gcc and finally use the resulting C++ compiler to compile the
      final version of gcc.

      I have a system with a C++ compiler but the system is not POSIX compliant. Can I build GCC on it in some way?

    3. Re:Compiler bootstrapping? by Anonymous Coward · · Score: 0

      http://vmakarov.fedorapeople.org/spec/

  18. Re:too bad GCC is not relevant anymore thanks to L by Carewolf · · Score: 4, Informative

    This is the first I've heard of anything like this. Did I miss something? Is GCC now GPLv3, and does that mean you can't use it to build non-GPL programs?

    No, it means when you go in and add extra functions to GCC that those would have to be GPLv3 as well, at least if you want to distribute them.

    It has NO effect on what the use of the application. In fact that is has no effect on the end user is one of the topmost clause of the GPLs.

  19. libgcc and libsupc++ by tepples · · Score: 3, Interesting

    What does a distribution license have to do with a compiler?

    Division support in C on some platforms (such as ARM) and exception support in C++ rely on libraries called libgcc and libsupc++. These libraries are GPLv3 with an exception. Were it not for the exception, anything compiled with the would either be GPL (because of libgcc and libsupc++) or produce a linker error (because the libraries are called and not present). The exception applies only if the compiler has not been modified to introduce non-free optimization passes performed in an independent process. See GCC Exception FAQ.

    Who does believes in GPL cuties? Apple, FreeBSD, 6 year olds, anybody else?

    You can add Nintendo. See the case of Pajama Sam for Wii, where Atari was willing to distribute the source code to a GPL interpreter used for the game but Nintendo didn't want GPL software on its platform.

    1. Re:libgcc and libsupc++ by Anonymous Coward · · Score: 1

      Were it not for the exception, anything compiled with the would either be GPL (because of libgcc and libsupc++) or produce a linker error (because the libraries are called and not present). The exception applies only if the compiler has not been modified to introduce non-free optimization passes performed in an independent process.

      Yes, this is true. The intent here is that merely compiling code should not impose any GPL restrictions to the code you're compiling, but if you make improvements to the compiler you should release those improvements back to the community. If you don't like this, you can go and make non-free optimization improvements to somebody else's compiler. The feature is working as intended.

    2. Re:libgcc and libsupc++ by Anonymous Coward · · Score: 2

      flaminyon

      Holy shit. Really?

    3. Re:libgcc and libsupc++ by JesseMcDonald · · Score: 3, Informative

      Were it not for the exception, anything compiled with the [gcc compiler?] would either be GPL (because of libgcc and libsupc++) or produce a linker error (because the libraries are called and not present).

      I think you mean "linked with libgcc/libsupc++". One can compile code with gcc/g++ without linking against the bundled libgcc. For example, the BSD-licensed libcompiler-rt library produced for the LLVM project is said to be a drop-in replacement for libgcc, and as a bonus, it's even a bit more efficient. If the same is not already true for libsupc++, I'm sure it's only a matter of time.

      --
      "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
    4. Re:libgcc and libsupc++ by Anonymous Coward · · Score: 0

      flaminyon

      Er, I think you mean "filet mignon". "Flaminyon" is not even a word.

    5. Re:libgcc and libsupc++ by Anonymous Coward · · Score: 0

      flaminyon? Did you mean Filet Mignon? If a homeless guy asks for flaminyon, My best guess would be to pour his vodka on the street and light it. Its flaming on.

      I'm not sure I want to take licence advice from someone who sucks at sacrasam that much. Maybe you should stick to car analogies and leave culinary analogies to people of more refined tastes.

  20. More like "C with Classes" by Megane · · Score: 5, Informative

    I've read their guidelines, and they're doing much like I've been doing recently with moving from C to C++ for embedded systems programming, which is to avoid the really crazy shit that you can do in C++. In particular, exceptions and RTTI are absolutely verboten. They're even planning a compiler switch that turns off the features that will be outlawed in the compiler source. Any templates outside of STL are also forbidden ("template hell" sucks), and I won't even use STL myself because I can't count on having a heap. Even iostreams are being frowned on except maybe possibly in debug dump code where no text language translations are needed.

    C++ can really tidy up C code that uses any sort of function pointer hooks or object dispatch style switch statements with virtual methods. A class can become a mini-API, and even used as a sort of device-driver, as in the mbed libraries. Doing this has really helped improve encapsulation in my own code.

    --
    #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
    1. Re:More like "C with Classes" by timeOday · · Score: 1

      They're even planning a compiler switch that turns off the features that will be outlawed in the compiler source.

      That is an interesting avenue. As languages like C++ and perl can attest, languages can evolve by adding features but it's almost impossible to take them back. Having a compiler flag to enforce a coding standard is a way to do that less coercively.

      Maybe this will result in a popular new dialect of C/C++.

    2. Re:More like "C with Classes" by Trepidity · · Score: 1

      If you just want more "batteries included" data structures than libc has, rather than anything else from C++ as an actual language, linking with GLib is a common alternative.

    3. Re:More like "C with Classes" by Ed+Avis · · Score: 2

      It's a strange mindset to see run-time type information, available by standard in widespread languages such as Java and C#, as 'really crazy shit that you can do in C++'. It carries a runtime cost and the only unusual thing about C++ is that you don't have to pay that cost if you don't use it. There is indeed crazy shit like compile-time Turing-complete template metaprogramming (the 'Vogon liver' that has grown way beyond its original intended purpose) but it's important to distinguish between that and language concepts which are quite normal and accepted in the rest of the world.

      --
      -- Ed Avis ed@membled.com
    4. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      At Google, exceptions and RTTI are also verboten. The code generated is still a heck of a lot more about C++ than C.

      C++ with a style guide is vastly superior to C. Strings and vectors for those of us who do have a heap... private member functions and variables... inline functions instead of macros... namespaces... type safety on stuff like sort and callbacks... Never understood why anyone would choose C over C++. Yes bad people write bad C++ code, but bad people also write bad C code - just with different problems. Get good people and worry about which language is better for good programmers. IMO it's a hands-down win for C++.

    5. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      It's crazy if you have the C programmer's "portable assembly" mindset. I actually learned more C++ before C. When I realized that my array of Boolean objects in C++ was an order of magnitude more memory intensive than the bit-arrays I could create in C, I became a C convert and never looked back. This is what I get for cutting my teeth with the roughly 40k of RAM available for my programs on the C-64. Keeping track of the fact that it's a pointer to a bunch of bits is a small price to pay for being able to reliably filter packets on a high-speed network.

    6. Re:More like "C with Classes" by Aidtopia · · Score: 5, Informative

      In particular, exceptions and RTTI are absolutely verboten.

      Ignoring RTTI is fine, but forbidding exceptions requires a dangerous sort of doublethink. The language itself, as well as the STL, is defined to generate and use exceptions. By ignoring their existence, you banish yourself to a nonstandard purgatory.

      For example, every new now must become new(std::nothrow). For every STL container type, you have to provide a custom allocator that doesn't throw. That's a bit unwieldy.

      By denying exceptions, you force everyone to use error-prone idioms. For example, the only way a constructor can signal a failure is to throw an exception. If you forbid exceptions, then all constructors must always be failure-proof. And then you have to provide an extra initializer method to do the real initialization that can fail. Every user of the class must reliably call the init method after construction, which gets cumbersome when classes are nested or when you're putting instances into an STL container. It also means that objects can have a zombie state--that period of time between construction and initialization. Zombie states add complexity and create an explosion in the number of test cases. Separate initialization means you can't always use const when you should.

      Exceptions are necessary to the C++ promise that your object will be fully constructed and later destructed, or it will not be constructed at all. This is the basis of the RAII pattern, which just happens to be the best pattern yet devised for resource management. Without RAII, you will almost certainly have leaks. Worse, you won't be able to write exception-safe code, so you are essentially closing the door to ever using exceptions.

    7. Re:More like "C with Classes" by Anonymous Coward · · Score: 1

      An array of Booleans in C is just as memory intensive as an array of booleans in C++. You known you can directly flip bits in C++ too. That's hardly a reason to stop using the language.

    8. Re:More like "C with Classes" by VortexCortex · · Score: 2, Insightful

      I've gone the opposite direction. Moving more of my C++ code into C by using my own OOP system. Before you say "That's crazy talk", consider that it makes inter-operating with my game's scripting language so much more buttery smooth than in C++ -- It's so nice to just create a new object in either script or C and have them talk to each other without going through a few layers of APIs, passing off dynamically allocated instances and having C free it, or the script GC it automatically.

      Don't get me wrong, I love C++, but they have rules that are conflicting when you get "deep" into the language. Try using multiple inheritance and polymorphism... It almost works, but not if you have two base classes with the same virtual function names -- That's just one of many edge cases I ran into... Theres several corners we're forbidden to go where templates, type safety, and inheritance don't play well with each other...

      After a while I just scratched my head, "Really C++? Really?!" Why would you have features that are incompatible? So long as I only use some of C++'s features some of the time, then everything is fine, but when I needed to use MOST of the language in the implementation of my scripting language, then shit hit the fan. Many experience people I look up to have told me if I need to use the WHOLE C++ language then I'm doing it wrong. To them I say: If you can't use the entire language at once then the Language is "doing it wrong".

      C++ is great if you're only using C++, and C++ constructs. That you have to use extern "C" { ... } to make shared libs that will actually work with other compilers or languages is a serious show-stopper for me. Protip: method names are munged into unique C function names so you can actually compile "C++", ergo they need to standardize name munging rules but to do that would be to admit that C++ is mostly implemented as a fancy pre-processor for C...

      Most of my C++ code was contained in extern "C" blocks, and I had abandoned most of the C++ features for my own language's simpler implementations, so one day I woke up and realized I should stop fighting C++ and just use C.

      My problem was that I needed a language that let me closely express the construct of another language within it -- embedability was a prime factor. Sure I could write the VM in C++, and have a ton of interfaces and abstraction and overloaded operators, etc, but with C I didn't need to do that.

      Some of the reasons I left C++ for are being fixed / added in C++2012, but it's too late for me. I'm not going back. I'll use C++ for my C++ only projects, but for anything that needs to work with other languages (most of my code), then I'll use C. Bonus: Instead of 15 minutes to compile the C++ implementation, it takes just seconds as C.

      C has many pitfalls, but at least they're out in plain sight; Unlike the C++ pitfalls, which are hidden in corners, shrouded in "advanced feature" mystery, and blanketed by the fog of denialism -- When things that should work according to spec don't (because of the implementation details), then you do you really have a language, or is it just part of a language?

      C++ has the same problem with C that I experienced with C++ -- When you try to implement a language in a way that's really close to another language, so you can use its underlying tool-chain, you run into a point where you must be shackled by the base language's implementation details... You can either build around the limitations (what C++ does), or you can embrace them (what I've done). Unfortunately I couldn't embrace the C++ implementation -- a complete one doesn't exist.

    9. Re:More like "C with Classes" by inglorion_on_the_net · · Score: 1

      This could work well. Indeed, there is something to be said for having C with a few extensions being a lot better for application programming than plain C.

      On the other hand, a lot of real-world C++ code is as crappy as it is exactly because people write it as if it were C with a few extensions, rather than taking advantage of other C++ features that would make it actually nice to read.

      As an example of this, it helped me a lot when I finally realized that, in C++, you can use almost any well-implemented type as if it were a primitive type like int. Memory management in C++ is a bitch and leads to lots of ugliness, but, in most cases, it simplifies to having your object created at declaration time and destroyed when it goes out of scope, much like an int would.

      On the gripping hand, you can't use the approach that makes C++ nice to read in all cases. Because you have to call an object's destructor exactly once, after the last time the object is used and before the last reference to the object is lost, you need some way to keep track of this. This is where a lot of the complexity in C++ programs comes from, and a lot of the bugs, as well.

      I wish the GCC developers good luck. I'm happy they're switching to a more expressive language than C. I don't know if C++ is the best choice they could have made, but time will tell.

      --
      Please correct me if I got my facts wrong.
    10. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      But then you have to deal with the horde of C++ purists that yell at you for not using objects, that there is no such thing as C/C++, and that you have a strange mindset or are using a dangerous sort of doublethink.

    11. Re:More like "C with Classes" by Carewolf · · Score: 0

      Ignoring RTTI is fine, but forbidding exceptions requires a dangerous sort of doublethink. The language itself, as well as the STL, is defined to generate and use exceptions. By ignoring their existence, you banish yourself to a nonstandard purgatory.

      No you don't. Forbidding exception is de-facto standard for C++ programmers, exceptions are an unsafe feature that integrates extremely poorly with most programming paradigms C++ is used for, every good C++ programmers disable them. If you enable exceptions, then you are using C++ in a way no one but programming students does, and could end up in all kind of bugs by doing untested things.

    12. Re:More like "C with Classes" by swillden · · Score: 3, Insightful

      When I realized that my array of Boolean objects in C++ was an order of magnitude more memory intensive than the bit-arrays I could create in C

      Dude, std::vector<bool>. All of the iterable, dynamically-resizable, type-safe goodness of a real array type with very nearly all the efficiency (time and space) of hand management of packed bit arrays. The only downside is that you do have a little extra bookkeeping info (an int) to support the dynamic resizing. If you need to avoid even that, there's also std::bitset, which has a length fixed at compile time. Odds are that code using std::bitset will be more efficient than what you'd write, and you don't have to waste brain cycles on "keeping track of the fact that it's a pointer to a bunch of bits".

      There are some reasons to prefer C over C++, but your example is decidedly not one of them. In fact, it strongly favors C++.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    13. Re:More like "C with Classes" by swillden · · Score: 2

      +1

      The only downside to C++ vs C, IMO, is the C++ learning curve. You have to learn all of both language, and how their respective constructs get translated to machine code and when to use what. However, once you've done that, and internalized it all, you can write highly efficient code at a much higher level of abstraction, making you much more productive. And you can also drop down to low-level bit-twiddling when you need to, wrapping it in a higher-level abstraction or not, as appropriate.

      If you have staff with the capability and education to use C++ effectively, it's a far better choice than C. If you're struggling to find good people... stick to Java or C#.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    14. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      And you seem to not even know that there is no way to know what std::vector will actually do.
      I believe some implementations actually conciously decided to make it behave like std::vector because it can be a lot faster.
      So if you're unlucky a little compiler change makes your application use 32 times as much memory and thrash the cache.

    15. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      The lack of designated initializers makes C++ a hand-down loser to me. You want a sparse 4 kB array that will be shared between multiple program instances (i.e. in .rodata)? Decide between writing a code generator for it or typing a few thousand zeros.

    16. Re:More like "C with Classes" by swillden · · Score: 1

      No, the standard defines the bool specialization, which must be space-efficient. There are some issues with std::vector, in that it behaves a bit differently from all other std::vectors, but the space-efficiency requirement is why it does that.

      --
      Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
    17. Re:More like "C with Classes" by Anonymous Coward · · Score: 1

      Can't tell if troll... or stupid.

    18. Re:More like "C with Classes" by Aidtopia · · Score: 1

      "Disabling exceptions" is a non-standard extension to the language. If you disable exceptions, you're technically not using C++ but a nonstandard dialect.

      What does it even mean to disable exceptions? I'll assume it makes new behave like new(std::nothrow), but is your STL implemented in a way to deal with that? It probably expects a failed allocation to throw. If it also has to check for nullptr, then there's another code path that's probably not well tested. What should std::vector::at do when faced with an out-of-bounds index? The standard says that it shall throw an exception.

      Disabling exceptions is different than simply not using a feature you don't want to use. If you don't want to write a template, that's fine. If you don't take advantage of dynamic_cast, that's OK, too. If you choose not to use STL and avoid the standard new operator and don't use RAII, then I suppose you can reasonably ignore exceptions. But STL and new and RAII constructors that fail will throw exceptions. You can choose not to catch any of those, but that doesn't mean that exceptions don't exist.

    19. Re:More like "C with Classes" by 21mhz · · Score: 1

      Can't tell if troll... or stupid.

      My bet is, a C++ programmer with some experience on real-world projects.
      It's true: C++ exceptions are broken. Don't use them.

      --
      My exception safety is -fno-exceptions.
    20. Re:More like "C with Classes" by 21mhz · · Score: 1

      I've gone the opposite direction. Moving more of my C++ code into C by using my own OOP system. Before you say "That's crazy talk",

      I say "that's like GObject".
      Works wonders, has dynamic typing and introspection, and it's even got a real high-level language these days.

      --
      My exception safety is -fno-exceptions.
    21. Re:More like "C with Classes" by 21mhz · · Score: 1

      It's a strange mindset to see run-time type information, available by standard in widespread languages such as Java and C#, as 'really crazy shit that you can do in C++'.

      Because it can either work correctly, or be fast. Pick one.

      --
      My exception safety is -fno-exceptions.
    22. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      The only downside to C++ vs C, IMO, is the C++ learning curve.

      It is not a curve but a surface since it keeps running away while you are learning.

    23. Re:More like "C with Classes" by maxwell+demon · · Score: 1

      Then hide your bit array in a nice class interface and show off as the hero of OOP.

      Or note that this already has been done by the developers of C++, and packaged into a nice class with name bitset.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    24. Re:More like "C with Classes" by maxwell+demon · · Score: 1

      Since GCC already uses a home-grown garbage collector, I guess they'll extend that to deal with C++ objects as well.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    25. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      You can't "don't use them", the C++ itself uses them.
      Write exception-safe code and use them properly.
      They're better than the alternative.
      (Professional C++ developer for many years on real-world projects...)

    26. Re:More like "C with Classes" by shutdown+-p+now · · Score: 1

      But then you have to deal with the horde of C++ purists that yell at you for not using objects

      Any person who yells at you for not using objects is a Java (or maybe Smalltalk) purist who happens to write C++ at the moment, not a C++ purist. Idiomatic C++ is not and never was about "everything is an object".

      Anyway, the correct answer to such inane demands is to tell them that everything in your code is an object, and then cite the definition of "object" from the standard, namely:

      "An object is a region of storage."

      So, yes, in C++ parlance, a bool or an int is an object.

    27. Re:More like "C with Classes" by shutdown+-p+now · · Score: 2

      Forbidding exception is de-facto standard for C++ programmers

      This is plainly false. In 7 years of writing C++, I've yet to work on a project where exceptions were forbidden. And the sky hasn't fallen, quite the opposite. Specifically:

      exceptions are an unsafe feature that integrates extremely poorly with most programming paradigms C++ is used for

      The primary programming paradigm that C++ enables is RAII. And RAII integrates extremely well with exceptions - in fact, it's pretty hard without them.

    28. Re:More like "C with Classes" by shutdown+-p+now · · Score: 1

      For example, every new now must become new(std::nothrow). For every STL container type, you have to provide a custom allocator that doesn't throw. That's a bit unwieldy.

      It's more than unwieldy, actually. Imagine that you're writing such an allocator, and new(nothrow) returned null to you. How are you going to report that to your container? The contract for the allocator has no means of reporting an allocation error other than throwing.

    29. Re:More like "C with Classes" by david_thornley · · Score: 1

      Couldn't you use smart pointers to determine when to call the destructor? They integrate memory management into C++'s RAII-based resource management. This is at least conceptually cleaner than the system whereby you use GC for memory and fake it (or use IDisposable or something) for everything else.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    30. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      Can you point out where exactly is "STL" mentioned in the standard? I see this acronym repeated everywhere by retards and would like an explanation because it's too widespread and is completely ambiguous... Do you really think the standard containers have anything to do with the standard template library? Are you referring to the standard library itself? Are you referring to something else altogether?

      If you answered YES to the first question, then do you also refer to the standard library as Boost (considering that some of its features have been inspired in Boost's)? If you answered YES to the second question, why call the standard library STL rather than STD which at least is the namespace the standard has reserved for it? If you answered YES to the third question, then what the hell is the "STL"?

    31. Re:More like "C with Classes" by Deorus · · Score: 0

      On the other hand, a lot of real-world C++ code is as crappy as it is exactly because people write it as if it were C with a few extensions, rather than taking advantage of other C++ features that would make it actually nice to read.

      Usually I stand for C++ in these debates, but here I have to draw the line, because as an experienced developer I can tell you that writing clean C++ code requires a huge investment of time. For example: a container implementation that can be written in 6 lines of C macros can extend for thousands of lines of C++ code just to make it compliant with the standard library's containers of the same kind so that it can be used in generic programming as well as with C++'s algorithms, and it's not the container alone, the main container (collection) may require a secondary container (bucket) to store individual elements in cases of non-linear access time (such as B-trees, lists, and graphs), and depending on the type of container, also an iterator with input, output, forward, sequential, and random access capabilities, all of this for const and non-const qualified access, with appropriate template specializations for specific algorithms, and if you really care about performance, a specialized atomic version. Oh and don't even get me started about streambufs or stream manipulators! Iostreams alone make me glad that the C standard library is part of the C++ standard -- iostreams are extremely slow and seem to have been designed by idiots.

      As an example of this, it helped me a lot when I finally realized that, in C++, you can use almost any well-implemented type as if it were a primitive type like int. Memory management in C++ is a bitch and leads to lots of ugliness, but, in most cases, it simplifies to having your object created at declaration time and destroyed when it goes out of scope, much like an int would.

      Memory management in C is even worse since it doesn't implement RAII (stuff getting properly destroyed when its duration time expires or an exception is thrown).

      On the gripping hand, you can't use the approach that makes C++ nice to read in all cases. Because you have to call an object's destructor exactly once, after the last time the object is used and before the last reference to the object is lost, you need some way to keep track of this. This is where a lot of the complexity in C++ programs comes from, and a lot of the bugs, as well.

      That's why the Reference Counting paradigm was invented, so you don't have to keep track of ownership and can implement libraries that take ownership of objects provided by their users without being concerned with those objects being unexpectedly deleted. C++ implements that through unique_ptr (takes exclusive ownership of its pointee until the end of the pointer's life, at which point its pointee is destroyed), shared_ptr (takes shared ownership of its pointee and destroys it at the end of the pointer's life but only if no other shared_ptr is pointing to the same pointee), and weak_ptr (doesn't take ownership, allows access to the pointee as long as there is at least one shared_ptr pointing to it -- this is used to mitigate the potential for memory leaks caused by circular references when two objects could otherwise claim to own each other without being owned by anyone else).

    32. Re:More like "C with Classes" by Deorus · · Score: 1

      I've gone the opposite direction. Moving more of my C++ code into C by using my own OOP system. Before you say "That's crazy talk", consider that it makes inter-operating with my game's scripting language so much more buttery smooth than in C++ -- It's so nice to just create a new object in either script or C and have them talk to each other without going through a few layers of APIs, passing off dynamically allocated instances and having C free it, or the script GC it automatically.

      Ever heard of Objective-C? If you're going to use something stupid, at least use something that anyone else can pick up...

      Don't get me wrong, I love C++, but they have rules that are conflicting when you get "deep" into the language. Try using multiple inheritance and polymorphism... It almost works, but not if you have two base classes with the same virtual function names -- That's just one of many edge cases I ran into... Theres several corners we're forbidden to go where templates, type safety, and inheritance don't play well with each other...

      You know there's virtual inheritance to solve that diamond-problem, right? It's not rocket science!

      After a while I just scratched my head, "Really C++? Really?!" Why would you have features that are incompatible? So long as I only use some of C++'s features some of the time, then everything is fine, but when I needed to use MOST of the language in the implementation of my scripting language, then shit hit the fan. Many experience people I look up to have told me if I need to use the WHOLE C++ language then I'm doing it wrong. To them I say: If you can't use the entire language at once then the Language is "doing it wrong".

      Versatility isn't wrong.

      C++ is great if you're only using C++, and C++ constructs. That you have to use extern "C" { ... } to make shared libs that will actually work with other compilers or languages is a serious show-stopper for me. Protip: method names are munged into unique C function names so you can actually compile "C++", ergo they need to standardize name munging rules but to do that would be to admit that C++ is mostly implemented as a fancy pre-processor for C...

      Bullshit, name mangling is not part of the standard, the only reason why you see it is because YOUR implementation implements C++'s function signatures that way. Unlike C, functions in C++ are resolved not only by their names but also by the types of their arguments, meaning you can have multiple functions with the same name so long as their argument types vary (which is called function overloading). Since most other languages lack support for this, they had to define a way to tell the compiler that a specific set of functions should be resolvable by name alone, hence extern "C", which tells the C++ compiler to follow C's rules (and historically also extern "Pascal").

      Most of my C++ code was contained in extern "C" blocks, and I had abandoned most of the C++ features for my own language's simpler implementations, so one day I woke up and realized I should stop fighting C++ and just use C.

      If most of your code requires C linkage, you are either doing it wrong (not hiding the ugly bits inside proper classes that can be reused) or you're writing extremely modular code, in which case you should consider switching the modules to C++ rather than the C++ core to C.

      My problem was that I needed a language that let me closely express the construct of another language within it -- embedability was a prime factor. Sure I could write the VM in C++, and have a ton of interfaces and abstraction and overloaded operators, etc, but with C I didn't need to do that.

      Or maybe you made the wrong design decision to develop the same layer in two languages. Why didn't you write all the scripting code in the scripting layer and al

    33. Re:More like "C with Classes" by Deorus · · Score: 0

      It's true: C++ exceptions are broken. Don't use them.

      How are they broken?

    34. Re:More like "C with Classes" by Deorus · · Score: 0

      The lack of designated initializers makes C++ a hand-down loser to me. You want a sparse 4 kB array that will be shared between multiple program instances (i.e. in .rodata)? Decide between writing a code generator for it or typing a few thousand zeros.

      Standard C++ doesn't know what 'rodata' is, neither does standard C (by the way). Now that we've addressed this issue, could you please name the "winner" language in that scenario? Don't even try to mention an assembler, because that's a "code generator" and you've already ruled those out...

    35. Re:More like "C with Classes" by Anonymous Coward · · Score: 1

      While I agree with the thrust of your post, you are also being short-sighted.

      Every user of the class must reliably call the init method after construction, which gets cumbersome when classes are nested or when you're putting instances into an STL container. It also means that objects can have a zombie state--that period of time between construction and initialization. Zombie states add complexity and create an explosion in the number of test cases. Separate initialization means you can't always use const when you should.

      Bzzt. Wrong. There is an easy obvious hack to fix that problem: public static initialiser.

      class SeparateInit : public BaseClass {
      protected:
      SeparateInit(); // Constructor
      virtual int init(...) {
            int err = BaseClass::init(...);
            if (err != ERRCODE_SUCCESS) return err;
            stuff; // do init
            return ERRCODE_SUCCESS;
      }
      public:
      static int create(SeparateInit **object, ...) {
            *object = new (std::nothrow) SeparateInit();
            if (!*object) return ERRCODE_NOMEM;
            int err = (*object)->init();
            if (err != ERRCODE_SUCCESS) delete *object;
            return err;
      }
      };

      It's annoying boilerplate but it does have a simple regular pattern that avoids the issue. Obviously it only works on heap allocated objects, but stack locals generally should be simple and rarely have initialisation failure states [Smart pointers and such start as null, etc]. It's also possible to eliminate the init method by passing a pointer to an int as one of the constructor parameters then explicitly passing it to the base class, etc.

      class ErrCodeInit : public BaseClass {
      protected:
      ErrCodeInit(int *error, ...) // Constructor
          : BaseClass(error, ...)
      {
              if (*error != ERRCODE_SUCCESS) return;
              stuff; // do init
              *error = ERRCODE_SUCCESS;
      }
      public:
      static int create(ErrCodeInit **object, ...) {
            int err = ERRCODE_SUCCESS;
            *object = new (std::nothrow) ErrCodeInit(&err, ...);
            if (!*object) return ERRCODE_NOMEM;
            if (err != ERRCODE_SUCCESS) delete *object;
            return err;
      }
      };

      (This second design is actually used in Microsoft's DirectShow framework, make what you want of that)

      The real problem that exceptions solve is the "resources were needed to complete this operation" error, like std::vector::push(...). Push needs more memory, tries to allocate and fails, so it throws an exception. You can return an error code but, if reading C code has taught me anything, 50% of the time people don't check them. [Does anyone check the return value of fwrite; what about malloc? It can fail but checking for that is rare] Exceptions are easier to work with because you don't need a thousand if statements, just wrap the entire top-level function body in a try-catch and use a transactional design with self-cleaning destructors.

    36. Re:More like "C with Classes" by TranquilVoid · · Score: 1

      The C++ standard mandates a vector of bools be implemented as a bit string, so I'm afraid you switched languages for no reason :)

    37. Re:More like "C with Classes" by Ed+Avis · · Score: 1

      Quite right. Read The C++ Programming Language. Classes and objects are not explicitly mentioned until quite late on, although the early examples do use standard library concrete types such as string.

      --
      -- Ed Avis ed@membled.com
    38. Re:More like "C with Classes" by pdh11 · · Score: 1

      How are they broken?

      It's not that they're broken in themselves, it's that they've been added to a language that can't support them properly. People say, oooh, you must write exception-safe code. What they're saying is, there's a property the code needs to have, which a compiler cannot test for, which you can't even easily unit-test for. And without this property -- exception-safety -- the code is unsafe. (It's not the code that throws or catches exceptions that you need to worry about: it's routines whose callees might throw and whose callers might catch. Those routines have secondary control flows through them, ones you can't see, but which need to be correct for the program to be safe.)

      It's not an innovation of the TDD community to say, that if something in your code isn't tested, you can't swear it works. In particular, you can't swear it will continue to work when future maintenance occurs. Because exception safety can't be "defended" against future breakage, I don't think you can hand-on-heart deliver C++ software written with exceptions and claim that it works.

      I'm not against exceptions as a programming technique: I think they work great in managed languages such as Python, Java, or ML. In those languages, it's not possible to write code that isn't "exception-safe" in the C++ sense. That's where exceptions belong. Throwing exceptions through unmanaged code was a brave experiment on C++'s part, but it's a misfeature, and I've got more confidence in codebases which forbid that (despite whatever problems they have with two-stage initialisation) than codebases which don't.

      Peter

    39. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      It's not that they're broken in themselves, it's that they've been added to a language that can't support them properly. People say, oooh, you must write exception-safe code. What they're saying is, there's a property the code needs to have, which a compiler cannot test for, which you can't even easily unit-test for. And without this property -- exception-safety -- the code is unsafe. (It's not the code that throws or catches exceptions that you need to worry about: it's routines whose callees might throw and whose callers might catch. Those routines have secondary control flows through them, ones you can't see, but which need to be correct for the program to be safe.)

      This shows your ignorance. Use smart pointers, particularly unique_ptr (the others are optional in this case, though shared_ptr works too if you're following a Reference Counting paradigm) and you won't have a problem with exceptions. Smart pointers serve the purpose of claiming and enforcing ownership over dynamic-storage duration objects -- when a smart pointer with auto-storage duration is destroyed (such as when an exception is thrown), so is its pointee, and RAII guarantees that all auto-storage objects created between the function that caused an exception and the function that handled it are properly destroyed before the exception can even be caught.

      Every time I see someone make idiotic claims like yours I can immediately tell that you don't know C++ because you are invariable very easy to refute.

    40. Re:More like "C with Classes" by Carewolf · · Score: 1

      Well, in 12 years of C++ programming, I have never seen a project where exceptions were NOT disabled. Of course 10 years ago, they were generally too poorly supported and slow, but still all projects I have encountered since have stayed clear of them.

      I guess this means it depend on the field of programming then. In some fields they are used, in others they are never used.

    41. Re:More like "C with Classes" by Carewolf · · Score: 1

      Point allocation is only one problem, other much bigger issues are database transactions, data safety and especially thread synchronization. You can do smart-pointer like stuff to make sure the database transactions are rolled back or commited when the function is exited on irregular codepaths, but with the exception of very simply mutexes, the same can not be done for thread synchronization.

      It is much simpler to just disable exceptions, and deal with your errors the right way, by handling them.

    42. Re:More like "C with Classes" by shutdown+-p+now · · Score: 1

      I can imagine them being disabled in embedded applications. My experience so far has primarily been with desktop apps and client/server stuff (again, with a desktop client).

    43. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      Point allocation is only one problem, other much bigger issues are database transactions, data safety and especially thread synchronization. You can do smart-pointer like stuff to make sure the database transactions are rolled back or commited when the function is exited on irregular codepaths, but with the exception of very simply mutexes, the same can not be done for thread synchronization.

      First I have to ask exactly what any of this has to do with C++, because these problems can occur in any other language where the grandparent poster claimed that exceptions were OK.

      Second, I fail to see how mutexes could be a problem unless you are an incompetent buffoon and suck at designing software (in which case just find another occupation). A good class implementation unlocks all of its mutexes in its destructor, which is run when an exception is thrown.

      It is much simpler to just disable exceptions, and deal with your errors the right way, by handling them.

      No, it's not simple at all. Exceptions are essential to object-oriented programming as well as generic programming, only an incompetent buffoon would make such a retarded claim! Exceptions signal conditions in which an object has determined that it can not continue to exist because it has entered an invalid state, not using them results in behavior that is undefined by the classes of which you are a client; exceptions allow you to perform call chains by getting rid of the burden of checking return values of the time; exceptions are much easier to handle in a single spot than return codes; unhandled exceptions crash programs in relevant places that make them much easier to debug than untested error codes; and finally, because exceptions signal invalid states, they can also signal conditions in which your program has accidentally become non-deterministic, crashing it by default rather than letting it run in a potentially insecure state. Oh, almost forgot, current implementations don't disable the throw keyword when you disable exceptions, they just disable all the support for try / catch, so all exceptions are unhandled and crash the program (your lack of knowledge about this little detail says loads about your lack of experience and competence).

      Don't be ashamed, though, a lot of people have no talent!

    44. Re:More like "C with Classes" by cjoy · · Score: 1

      Why do you say that thread synchronization doesn't work with exceptions? Seems to me that this isn't that much different than database transactions. Grab the mutexes you need, perform the operations, commit on success, rollback / go to known state on failure. Release / destruct mutexes at end of transaction. Just like with normal exception programming the main point is to check that exceptions go to a known state.

    45. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      If you always crash on un-handled exceptions, you eventually lose some lives and property. Pacticularly so if mixing the various exception philosophies together in a single system. Sometimes you can't go all popping-the-stack like it's 1999 in a real time or embedded system.

    46. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      If you always crash on un-handled exceptions, you eventually lose some lives and property. Pacticularly so if mixing the various exception philosophies together in a single system. Sometimes you can't go all popping-the-stack like it's 1999 in a real time or embedded system.

      Moot point. Crashing on an unhandled exception gives you the certainty of knowing that the entire program entered an invalid state as well as the ability to debug it from the perspective of the moment when it went sailing on weed. The assumption is that if you are not handling an error, then your code is not prepared to deal with its side effects. Completely ignoring an error condition by default, however, leads to completely unpredictable results that can escalate over time to a huge mess that a crash would have prevented right from the start because from that point forward nothing in your code is guaranteed to function as expected.

    47. Re:More like "C with Classes" by Carewolf · · Score: 1

      There are other types of synchronization than just Mutexes, as I said, except Mutexes it is not trivially to do exception safe coding for synchronization. What the 'revert' or 'safe' state is, can vary from function to function, and you need to handle the cases explicitly, which is the opposite of what exceptions does. Exceptions makes the assumption that the code-path doesn't matter, and everything has a trivial way to unstack the state, this is rarely the case, and you are just adding more and more increasingly complex workarounds (unstacking pointers, transactions, mutexes) to make an obviously broken feature, almost work.

    48. Re:More like "C with Classes" by 21mhz · · Score: 1

      You can't "don't use them", the C++ itself uses them.

      Ah, but there's the ultimate exception-safety flag: -fno-exceptions
      No std::bad_alloc, no other invisible shit, no problem.

      --
      My exception safety is -fno-exceptions.
    49. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      There are other types of synchronization than just Mutexes, as I said, except Mutexes it is not trivially to do exception safe coding for synchronization.

      Again, why aren't you unlocking your mutexes in destructors?

      What the 'revert' or 'safe' state is, can vary from function to function, and you need to handle the cases explicitly, which is the opposite of what exceptions does.

      The parts that "vary from function to function" can be dealt with by binding the duration of the allocated resources (including the transactions and the mutexes) to the duration of the function, which as I mentioned before, can be accomplished through the use of either smart pointers with auto-storage duration or auto-storage objects. Provided that you bind stuff to the function's storage duration, C++ guarantees that it is properly destroyed when an exception is thrown; the complexity is entirely in your head because you don't know C++.

      Exceptions makes the assumption that the code-path doesn't matter, and everything has a trivial way to unstack the state, this is rarely the case, and you are just adding more and more increasingly complex workarounds (unstacking pointers, transactions, mutexes) to make an obviously broken feature, almost work.

      The only assumption that exceptions make is that objects know how to destroy themselves (if they don't, then the program is broken and should just abort as it doesn't really know how to recover from an error condition). There is absolutely no complexity here, at least not for anyone who actually knows OOP (let alone C++), which you clearly don't. If ignoring error conditions that you don't understand is your definition of simplicity then I'm sorry to tell you but I hope to never depend on your code for anything in my life, because you are an incompetent moron.

      How far do you wish to take this? I can continue to own your ass on this argument all day long if you like, just keep posting and I'll keep replying just so people can see how ignorant and utterly incompetent the C++ haters really are.

    50. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      (init() methods are quite recommendable! For fully reusable objects. I agree that a no exceptions requirement is good for the most general and reusable object libraries, just leverage their building complexity with long term reutilization).

    51. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      -fno-exception is not standard and even if you use it you still have to deal with the error conditions that caused the exception, but now in a more obtuse way (return values? error flags?) that is more likely to leave your program in an invalid state.

    52. Re:More like "C with Classes" by 21mhz · · Score: 1

      Yes, I have to deal with error conditions and bother about explicit API conventions for them, but doing it explicitly is still better than the way exceptions are wedged into C++.

      --
      My exception safety is -fno-exceptions.
    53. Re:More like "C with Classes" by badkarmadayaccount · · Score: 1

      Lack of a homogeneous type system is a valid argument for the Smalltalk purist. And that nice Self fella in the corner.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    54. Re:More like "C with Classes" by badkarmadayaccount · · Score: 1

      Gambit-C Scheme, Chicken Scheme.

      --
      I know tobacco is bad for you, so I smoke weed with crack.
    55. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      Last I checked compiling out exceptions did the new change automatically.

      If your general failure path is to abort the compile and die anyway, then constructor can call something that's going to end up calling abort() to notify failure.

    56. Re:More like "C with Classes" by Anonymous Coward · · Score: 0

      What is a Boolean object? Are you sure you're not talking about Java?

  21. Re:oh nooos by Samantha+Wright · · Score: 2

    RTFS—GCC itself is becoming a C++ program. It'll still compile stuff the same way. (Optimizing your compiler is for Gentoo users and communists.)

    --
    Bio questions? Ask me to start a Q&A journal. Computer analogies available for most topics!
  22. Awesome by Carewolf · · Score: 4, Insightful

    GCC as a compiler and a community seems to really be moving, it is probably due to the competition from LLVM, but atleast for now, GCC is still the better compiler, and I wish them the best of luck.

    Good compilers benefits everybody!

  23. Re:too bad GCC is not relevant anymore thanks to L by Lemming+Mark · · Score: 2

    I think there are a few non-ARM embedded platforms that use gcc. AVR (even the 8-bit variants) has a good gcc port.

  24. Re:too bad GCC is not relevant anymore thanks to L by petermgreen · · Score: 4, Interesting

    AIUI GCC is now GPLv3, the libraries it ships with are GPLv3 with exceptions that allow using them to build non-GPL programs. However they were paranoid about the idea that people would try and save gcc's internal state to disk and then run it through a propietry backend. So they crafted a complex exception that tries to forbid that while allowing most other combinations of gcc with propietry tools.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  25. Re:too bad GCC is not relevant anymore thanks to L by skids · · Score: 1

    Also Coldfire, and a bunch of those MIPS spinoffs, IIRC.

  26. bad_alloc by tepples · · Score: 1, Interesting

    or you have some very specific performance issues that you absolutely cannot fix any other way (and generally, you don't have this problem with the STL)

    On a platform with no swap file, such as a handheld or set-top device, one of the more common "very specific performance issues" is the ability to handle allocator failures. A program in such an environment is supposed to free cached or otherwise purgeable resources instead of just letting main() catch std::bad_alloc and abort. What are best practices for using the C++ containers if virtual memory is not available?

    1. Re:bad_alloc by squizzar · · Score: 2

      Is he referring to using containers as part of the target application or as part of the compiler itself? The compiler internals might be much cleaner or there may be less redundant code for the compiler if it used STL rather than alternative or custom containers etc. Your target application would still only be using STL if you wrote code to use it...

    2. Re:bad_alloc by Anonymous Coward · · Score: 1

      You're conflating two entirely different issues. C++ only addresses what happens when you run out of memory. Its cares not, and rightfully so, if that happens with or without virtual memory. Its also worth pointing out, many computers, even with paging, do not support Linux's notion of over commit.

      Your question is best addressed by simply saying, design your application properly and it won't be an issue. If it persists to be an issue, then by definition, you do not have the proper hardware. Please note, this is at no point in time, a language issue or constraint.

    3. Re:bad_alloc by VortexCortex · · Score: 2

      You write a damn exception handler block every time you have a "new". If you're using Linux and you run out of VRAM, it just starts killing processes until it has the memory. Its "optimistic" allocator doesn't throw std::bad_alloc -- is some really scary shit.

    4. Re:bad_alloc by Anonymous Coward · · Score: 0

      You can configure Linux to be less optimistic. Or even turn off overcommit.

    5. Re:bad_alloc by gbjbaanb · · Score: 1

      You don't need to write a exception handler for bad_alloc for 99% of cases, just write a bad_alloc handler for those areas where you try to allocate a large amount of memory.

      If you cannot alloc an object of 20 bytes or so, you've got problems no exception handling will solve. Exit gracefully and start again. If you cannot allocate 1mb, then maybe you can do something about it, handle those and ... probably exit gracefully anyway.

      It could be worse though, in .NET if you run out of stack, you don't even get the exception - it just exits.

    6. Re:bad_alloc by Dahamma · · Score: 1

      I've worked on dozens of embedded set-top platforms that use Linux /w GCC-based toolchain, and I don't remember a single one that had exception handling and RTTI enabled for any C++ code...

    7. Re:bad_alloc by Greyfox · · Score: 1

      If you don't care, you can just let the function you're in rethrow the exception to a higher level until something catches it or the application crashes. In practice you'll never get one of those -- the (Linux) operating system will just crash when it completely runs out of memory in the default configuration anyway. Which I think everyone will agree is MUCH better than some ill-behaved application crashing because it didn't handle a null back from a malloc correctly.

      --

      I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

    8. Re:bad_alloc by shutdown+-p+now · · Score: 3, Informative

      It could be worse though, in .NET if you run out of stack, you don't even get the exception - it just exits.

      You do get a StackOverflowException, actually. The catch - pardon the pun - is that it's a "magic" exception type that cannot be caught by user code, since .NET 2.0. So in practice it's only there for debuggers.

    9. Re:bad_alloc by shutdown+-p+now · · Score: 1

      That by itself means that you can't use STL, since it requires allocators to either return a block of memory or throw (in which case the exception is pass-through to the caller).

    10. Re:bad_alloc by larry+bagina · · Score: 1

      If you use -fno-exceptions, throwing an exception will just call abort(). Which is exactly what will happen if he has exceptions enabled but doesn't catch it, but without the extra overhead.

      --
      Do you even lift?

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

    11. Re:bad_alloc by shutdown+-p+now · · Score: 1

      Well, the OP specifically didn't want to abort on OOM, he wanted to gracefully handle it, e.g. by clearing any memory caches. abort() doesn't help there. It needs an replacement API that lets one propagate OOM conditions for all container operations and algorithms by means other than exceptions - i.e. an explicit error code, or perhaps the ability to register a handler (but then how that's really different from exceptions?).

    12. Re:bad_alloc by larry+bagina · · Score: 1

      std::operator new() will repeatedly call the new handler (std::set_new_handler()) if there's one installed (std::get_new_handler()) before throwing an exception (or returning NULL if exceptions are disabled or it was called with std::nothrow).

      --
      Do you even lift?

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

    13. Re:bad_alloc by jonwil · · Score: 1

      Anyone who is actually trying to run GCC itself (which is what the discussion on the use of STL is about) on a resource-constrained device like that is stupid.

    14. Re:bad_alloc by Anonymous Coward · · Score: 0

      To be completely fair, It doesn't seem to be *randomly* killing processes.

      It has never killed anything other than firefox for me.
      And lets be completely honest, firefoxs memory usage is *still* abysmally horrible.

      The mere fact that it can and does eat 4+GB of RAM while having ~20 pages open is completely unacceptable.
      IMHO it kinda deserves to be killed after 1GB. Especially since it can usually recover flawlessly.

    15. Re:bad_alloc by Anonymous Coward · · Score: 0

      You know you can turn that magic off at build time right?

    16. Re:bad_alloc by shutdown+-p+now · · Score: 1

      Given that the magic is purely runtime behavior, why would that be something that can be turned off at build time?

      Anyway, how exactly do you suggest to turn it off? It's "more special" than corrupted state exceptions like AV, so you can't even use [HandleProcessCorruptedStateExceptions] or legacyCorruptedStateExceptionsPolicy to make it catchable.

  27. Will keep compiling C properly? by Windwraith · · Score: 2

    That's all I really care about, to be honest. As long as I can keep coding in C, they can do whatever.

    1. Re:Will keep compiling C properly? by VortexCortex · · Score: 1

      Yep, it'll keep compiling C properly. The real issue here is compiling C++, not C. You see, C++ uses many of the C language implementation. Eg: Function names are munged into unique C function names prior to compiling...

      The C++ language is running into walls where C implementation details are difficult to work around. Moving the C compiler codebase to C++ allows C++ compiler to more easily advance. C itself will be largely unaffected, it just makes developing C++ easier.

    2. Re:Will keep compiling C properly? by Anonymous Coward · · Score: 0

      Name-mangling is because C++ has function overloading while the linking formats (usually) don't support symbol resolution based on argument types, so the argument types have to be encoded in the symbols. This is a limitation of the executable and linking formats rather than C, but it's hardly a limitation at all in practice, and completely separate from what language the compiler is written in. In fact, I'm not even sure what you are thinking of when you say that moving the C compiler code base to C++ will allow the C++ compiler to advance more easily? The C compiler has zero effect on the C++ compiler, and could be written in INTERCAL and would neither hinder nor help C++. Or do you simply mean that writing the compiler (taken here to mean the whole compiler suite) in C++ makes it easier for the gcc developers to write better code? Well, yeah, I guess that's the point of the switch, but for C++ developers using gcc the only impact will be that maybe gcc adheres stricter to the C++ standard (and compiles slower or faster...)

    3. Re:Will keep compiling C properly? by Jonner · · Score: 1

      That's all I really care about, to be honest. As long as I can keep coding in C, they can do whatever.

      if GCC, being written in C, has been compiling C++ correctly for many years, it seems a much easier task for a GCC written in C++ to correctly compile C. Also, GCC has been and will continue to be used to compile a great deal of C code so any regressions will be noticed very quickly.

    4. Re:Will keep compiling C properly? by TranquilVoid · · Score: 1

      Moving the C compiler codebase to C++ allows C++ compiler to more easily advance.

      This is unrelated. The job that a piece of software does is theoretically independent from the language. They are moving to C++ because they believe the language features better help them organise their codebase. You could write a C++ compiler in Java, Python, Lolcode - whichever language is best suited to parsing text, arranging it into expression trees, optimising those trees and writing out binary files. I don't think OpenCobol would benefit from being writting in Cobol rather than C!

      Unless I'm missing something in your comment..

  28. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 1

    GCC obviously comes with support libraries and tools. Those are covered under the GPL (although there are exceptions for libs used by programs).

    This means any distribution that ships GPLv3 binaries has to adhere to the terms of the GPLv3 in terms of distribution of source, etc. So in a perfect world, an embedded platform should not have any toolchain stuff on it, it is a risk that a developer will screw up someday and do it. This precludes the GPLv3 from use in FreeBSD as they are targeting companies like Cisco, Juniper, and of course the code sharing with Apple from time to time.

    Licensing is a tough decision and affects who will use your software and how it will be used. Not everyone accepts the GPL and some have irrational fears of it. The mention of the GPLv3 turns of use cases because of misinformation about how bad it is. For me, it took deciding that the tivo clause wasn't all bad to move forward. The patent bits aren't any worse than the Apache 2 license. It's just the image it has combined with the viral tradition it continues. At the end of the day it's not much worse than the GPLv2. Some of us just drew a line in the sand.

    Here's a list of BSD projects that ship GPLv3 code in their CURRENT code base:
    NetBSD (binutils, gcc, ...?)
    DragonFly (binutils, gcc, ...)
    MidnightBSD (just gnu diffutils right now, going llvm + clang for compiler)

    And GPLv3 avoiders:
    FreeBSD (switching to llvm + clang)
    OpenBSD (switch to pcc + old gcc?)
    MirBSD (old gcc, pcc)
    Apple OS X & iOS

    unknown but probably gplv3 avoiders:
    pfsense
    pc-bsd
    other distros of freebsd and openbsd

    In order to do gcc, you need binutils. Then you might as well add diffutils... then it spirals out of control.

  29. Re:too bad GCC is not relevant anymore thanks to L by keltor · · Score: 3, Informative

    Actually a number of the older embedded platforms I've programmed for DID in fact use gcc+patches, usually with proprietary stuff added all around. I believe for most of the microcontrollers supported by Keil, the compiler is based on GCC (often the older 2.x series.)

  30. OOM inside STL by tepples · · Score: 2

    In particular, exceptions and RTTI are absolutely verboten. [...] Any templates outside of STL are also forbidden

    What implementation of STL do you recommend for low-memory systems that have a heap, albeit not a very big one, where you don't want to crash upon running out of memory?

    Even iostreams are being frowned on

    In my experience (quarter megabyte static hello world), <iostream> would be the first to go, in favor of <cstdio>. See what else I've written about the pitfalls of C++ on small systems.

    1. Re:OOM inside STL by Anonymous Coward · · Score: 0

      Your "Templates" section requires some work. Your first point is completely true and accurate. Your second point, however, is extremely misleading. Your point of contention is in no way specific to C++ nor templates. It equally applies to any langauge which supports structures and/or classes. That's not C++ nor templates specific issue. Period.

      Your first point of contention about "Exceptions", is also false. People don't realize that exceptions do carry performance issues. MOST people simply fail to benchmark them properly. Many people are under the false impression that simply using or not using exceptions makes for a valid benchmark. This is almost universally false. Compilers which allow you to disable exceptions typically require an explicit compiler flag to tell it to disable exceptions. This is important as proper exception support requires different stack frames. Thusly, the performance delta stems from entirely different size stack frames, as required to support frame unrolling to support exceptions.

      The rule of thumb for GCC based compilers seem to be 8%-10% overhead. Though clearly that will dramatically differ based on how you use exceptions, the depth of calls, and the nature of the specific application in question. Regardless, when properly disabled/enabled, exceptions absolutely do carry a performance penalty. Whether or not the penalty is noteworthy for your specific application is a different story.

    2. Re:OOM inside STL by Anonymous Coward · · Score: 0

      Even on a machine with limitless resources iostream should be the first to go, unless you seriously believe that

      std::cout (bitshift left) std::hex (bitshift left) std::setfill('0') (bitshift left) std::setw(8) (bitshift left) x (bitshift left) std::dec (bitshift left) std::endl;

      is somehow superior to

      printf("0x%08xn", x)

      (apoligies for the "bitshift left", Slashdot eats up the actual operator.)

    3. Re:OOM inside STL by Anonymous Coward · · Score: 0, Troll

      Use the goddamn HTML entities you moron: &lt; &gt;
      Or create an account and use the D1 discussion system.
      << >>
      It's not rocket surgery.

    4. Re:OOM inside STL by Score+Whore · · Score: 1

      (apoligies for the "bitshift left", Slashdot eats up the actual operator.)

      <<

      And you want to be my latex salesman!

    5. Re:OOM inside STL by maxwell+demon · · Score: 4, Insightful

      Actually the correct comparison is to not only disable exceptions in the compiler, but in addition adding hand-crafted error handling to the code. Because manual error handling also costs performance. And without error handling, your application is broken, period (and yes, I have been bitten by applications doing improper error handling. And yes, that included data loss. Loss of data stored on the hard disk, because the application didn't do any error checking when replacing the file with a new version. Fortunately I could get back most of it from the nightly backup).

      --
      The Tao of math: The numbers you can count are not the real numbers.
    6. Re:OOM inside STL by Anonymous Coward · · Score: 0

      ROFL @ "rocket surgery"

    7. Re:OOM inside STL by Anonymous Coward · · Score: 0

      Good point.

      Holy crap. Its literally been months, maybe a year, since someone on slashdot actually contributed a valid answer to something I've corrected.

      Cheers to you.

    8. Re:OOM inside STL by Anonymous Coward · · Score: 0

      And yes, that included data loss. Loss of data stored on the hard disk, because the application didn't do any error checking when replacing the file with a new version. Fortunately I could get back most of it from the nightly backup).

      Uh, what?
      Accidental overwriting of a file on disk is a typical user error, not a programmer error. Or did the application fail to replace the old file with the new one?

    9. Re:OOM inside STL by maxwell+demon · · Score: 1

      It modified the file by writing a new file and then replacing the old file by the new file. So far, so good. The problem was that writing the new file didn't complete because it hit quota limits. The correct thing in that case would have been to keep the old file, remove the partially written new file and give an error message informing me that modifying the file didn't succeed. After all, that's the fucking point of that technique; otherwise they could just have written over the old file (ironically, had they done that, I would not have had any data loss, because the new file would have been smaller even if written completely). What it did was to ignore the problem, delete the old file and replace it with the partially written new file. The new file, if written completely, would still have contained all the data I cared about. The new file, as written, was lacking most of that data.

      --
      The Tao of math: The numbers you can count are not the real numbers.
  31. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    dont forget broadcom mips is also compiled using gcc, and that is a very large chunk of the embedded market

  32. Re:GCC should remain small and fast by arse+maker · · Score: 1

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    Cite real world benchmarks please.

  33. GCC Switches From C to C++ by Anonymous Coward · · Score: 0

    ... and there are still Mayan apocalypse deniers out there ?

    captcha : doomsday :D

    1. Re:GCC Switches From C to C++ by turgid · · Score: 1

      Argh! Whatever next...

      C and C++ are different languages. Why on earth the C compiler needs to be written in C++ I'll never understand. That means you can't compile the C compiler without a C++ compiler, and C++ is far more complex that C.

      C++ compilers are big, complicated and slow, and statistically more likely to contain bugs.

      If they were going to move to a "new" better language. they should have gone with something like D.

      But really, C ain't broke and it don't need fixing.

      C++ needs to be taken out and put out of its misery.

    2. Re:GCC Switches From C to C++ by Deorus · · Score: 0

      C++ compilers are big, complicated and slow, and statistically more likely to contain bugs.

      Agreed, they should have stuck to BrainFuck! With only 7 instructions, the likelihood for bugs is pretty small, and since there's absolutely no way the compiler could make an attempt to guess what you're doing, you don't even have to deal with optimization bugs!

  34. Re:GCC should remain small and fast by serviscope_minor · · Score: 5, Insightful

    I used to be more polite to ignorant C++ haters. But I've lost patience.

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    There is a way around it: by not being an astonishingly incompetent developer.

    And that's without even getting into features like templates, which only five people in the world understand.

    Don't assume everyone is as dim as you.

    --
    SJW n. One who posts facts.
  35. C++ is Dead, Long Live Java by Anonymous Coward · · Score: 5, Funny

    C++ is as good as dead.

    Everything should be written in java, since this would give a huge speed increase.

    For even more speed, programs could be run on a java interpreter, running on a java interpreter written in java.

    Think of the raw speed!

    1. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      Agreed. And remember...the very FIRST program you should write in any programming language is "remove comments"...as we all know that spurious comments slow down your program at runtime. Plus, "remove comments" is far more useful than that utterly useless "hello world" program...

    2. Re:C++ is Dead, Long Live Java by BobNET · · Score: 1

      For even more speed, programs could be run on a java interpreter, running on a java interpreter written in java.

      It's Java interpreters all the way down!

    3. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      C++ is as good as dead.

      Everything should be written in java, since this would give a huge speed increase.

      For even more speed, programs could be run on a java interpreter, running on a java interpreter written in java.

      Think of the raw speed!

      While we're at it, let's speed things up more by just piping everything to /dev/null.

    4. Re:C++ is Dead, Long Live Java by smittyoneeach · · Score: 1

      Java: continually re-inventing the wheel, in search of additional roundness!
      And so you arrive at J2EE projects on apache.org where these geniuses are writing XML configuration files which, through Reflection, essentially become scripts against the JVM.
      Sometimes I wish Java could suck more.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    5. Re:C++ is Dead, Long Live Java by gman003 · · Score: 0

      Sometimes I wish Java could suck more.

      Good news! Microsoft has heard your plea, and responded with C#! It has all the features of Java, plus the extra feature of only working right on Windows!

    6. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      You're not actually that far from the truth (well, not the java interpreter part)..

      C++ has a real problem now because it's squished in the middle. Basically for many business apps that don't care about speed, .NET and/or Java and the like are good substitutes for C++ because they're "safer".

      And for those companies that DO care about speed, C is still the best choice because you can easily tell what's going on without all the confusions that Templates, RTTI, Exceptions, and so on, that C++ brings to the table.

      So C++ is still fighting a war on two fronts. And I anticipate its overall usage will continue to decline. Though perhaps some of the new features in the recent standard might stem the bleeding for awhile.

    7. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      gman, meet Mono framework. Mono framework, meet gman.

    8. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      ... plus the extra feature of only working right on Windows!

      Anonymous Coward, meet the English Language. English Language, meet Anonymous Coward.

    9. Re:C++ is Dead, Long Live Java by boddhisatva · · Score: 1

      Runs on an interpreter = raw speed? You have lost your mind. You really ought to look into how computers work. At least C++ is compiled. Java sucks. Java promised code reuse - not only is there no code reuse but changes to Java mean that 30% of Java programmer time is spent maintaining legacy code. Infrastructure, how many different infrastructure components have you gone through? Is it more than 10? Bjarne Stroustrup said "C lets you shoot yourself in the foot. C++ makes it harder but if you do it blows your whole leg off." There is a clue in there. C++, Java and OOP in general were created to keep mediocre programmers from screwing up too much. Carnegie Mellon has dropped OOP as a requirement for Comp Sci saying that it's outdated and will no longer be useful with modern hardware. Done any heterogeneous parallel programming? Are you comfortable with non-deterministic code? I'm 63 and you young turks remind me of the COBOL programmers at the home for ossifying techies. Gotta keep movin' son.

    10. Re:C++ is Dead, Long Live Java by bobdickgus · · Score: 1

      Whoosh!

      --
      Yes i am posting this from work like you.
    11. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      The only thing that sucks more than java is... java developers... :-)

    12. Re:C++ is Dead, Long Live Java by Anonymous Coward · · Score: 0

      I know you're joking, but modern compilers actually do tend to run the way of Java. Look at clang, which generates intermediate code for llvm, just like javac generates bytecode. You lose a bit of theoretical optimization potential but gain a huge instrumentation potential, meaning neat things such as the ability to rewrite code while it's running, analyze memory management, increase security, etc. While Java would never be able to achieve the same performance as C or C++ due to lacking raw pointer support as well as non-dynamic memory allocations, its implementation is not considered conceptually wrong even for performance.

    13. Re:C++ is Dead, Long Live Java by TangoCharlie · · Score: 1

      You're almost right. Actually, JavaScript is the new C. The GNU Compiler Collection should now actually be ported to JavaScript. I also suggest that a new UI be created using HTML5. It's about time GCC was tightly coupled to an IDE so we can move away from the command line.

      --
      return 0; }
  36. Re:too bad GCC is not relevant anymore thanks to L by VortexCortex · · Score: 4, Funny

    I assure you your refrigerator temperature thermostat was not programmed in GCC.

    That's because its CPU is a bi-metallic strip wound into a coil, and it's RAM is only one bit. The equivalent of running .configure and make is rotating a dial and tightening a screw.

  37. Re:too bad GCC is not relevant anymore thanks to L by DeathToBill · · Score: 4, Interesting

    Well, let's see. I personally work with control systems using x86, MIPS, PowerPC and ARM architectures, running Linux, VxWorks, QNX and WinCE (various combinations). They all have GCC toolchains, although we admittedly don't use it for CE.

    If you're thinking microcontrollers, then GCC supports AVR, 68000-series, MicroBlaze, MSP430, ARM again...

    Now, personally, my refrigerator has an analog thermostat, so, technically, you are right. If it had a thermostat implemented on a CPU, then I'd think there's a very good chance it was compiled with GCC.

    What exactly "programmed in GCC" might mean is left for the reader to speculate on.

    --
    Slashdot - News for Nerds, Stuff that Matters, in ISO-8859-1 Has just realised that beta makes this signature redundant
  38. Re:too bad GCC is not relevant anymore thanks to L by DeathToBill · · Score: 1

    I also note with curiosity that the one vendor you can actually name with a competing compiler is a development environment aimed primarily at ARM and is, in fact, produced by the "elitist, narrow though visible" ARM.

    --
    Slashdot - News for Nerds, Stuff that Matters, in ISO-8859-1 Has just realised that beta makes this signature redundant
  39. Stupid Answer Follows by Anonymous Coward · · Score: 0

    Aslong I can write my own C Compiler, I do not mind.
    I wounder if you other guys can say that about your favorit language?

    1. Re:Stupid Answer Follows by Ash-Fox · · Score: 1

      Could you write a spell checker first?

      --
      Change is certain; progress is not obligatory.
  40. Re:oh nooos by petermgreen · · Score: 2

    Which is a complier more likely to be able to optimise? polymorphism that is explicit in the language or polymorphism that is hacked together by creating vtables (which are basically structures full of function pointers) manually? Which is more likely to have mistakes made that associate the wrong vtable with an object?

    C++ has it's problems but it's the only widely supported language that both provides OOP features and yet still allows the writing of tight code where needed.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  41. Re:GCC should remain small and fast by Anonymous Coward · · Score: 1

    Small and fast?
    Have you looked at the GCC source code?
    I don't know about fast, since I haven't actually compared the performance to other compiler.
    However, GCC contains all kinds of code for which using classes would be absolutely ideal.
    Basically most things are already programmed into a kind of class, only using C.
    By switching to C++ you can formalize all these things.
    Instead of having to manually maintain a list with function pointers to specific functions that you need for a certain target,
    or a certain scheduling pass you can make it into a class, and the compiler does all the work for you.
    That eliminates lots of code right then and there.

    For example, every GCC back end has to define specific functions that will be called by the compiler when transforming the RTL into instructions.
    So somewhere in every back end there is a file with 100 or more defines of functions to specific macro names, that are in turn used in a different file to map the correct function that you define into an array of function pointers.
    If instead you make a class that defines all the functions as abstract methods, all you have to do is inherit from that class and provide the implementation.
    For every function that gets rid of one
    #undef MACRONAME
    and one
    #define MACRONAME somefunction

    There are examples of things like this throughout the source code.
    The other advantage is that you can have the interface of a back end specified in a single class, instead of spread out over several header files that you have to know to look for.

  42. my fridge thermostat is digital by Chirs · · Score: 1, Offtopic

    It's got digital temp settings for fridge/freezer compartments, an optional "super-cool" for fast-freezing the freezer section after putting a load of groceries into it.

    Once of the coolest fridges I've seen (don't own it, too expensive) actually learned your habits--if you always have breakfast at time X and it generally results in the temperature in the fridge warming by a degree, it will pre-cool by an extra degree at time X-1 so that when you open it for breakfast it will warm up to the desired temperature. That fridge also had three separate compressors, one for each side of the fridge and one for the freezer. They were all variable speed, ran just fast enough to keep the desired temperature rather than cycling on/off.

    1. Re:my fridge thermostat is digital by aztracker1 · · Score: 2

      Which should bring us back to a point... how do *you* know the fridge isn't using logic compiled by GCC?

      --
      Michael J. Ryan - tracker1.info
  43. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    I know it's something else, but _compiling_ C++ code is sure horribly slow and uses loads of memory.
    With gcc 4.7 they started using C++ and I haven't been able to compile that on a PPC Mac mini with 2GB of RAM without disabling any system service I could and not doing anything else on it.
    gcc 4.6 could be compiled just fine, and you could even do some browsing at the same time.

  44. Re:GCC should remain small and fast by Anonymous Coward · · Score: 1

    don't assume you're as smart as you think you are.

  45. Are ABI compatibility issues still a problem? by Anonymous Coward · · Score: 0

    I remember not too far back, new g++ versions forced all the C++ code to be rebuilt in your distro repository.
    Is this a concern any longer?

  46. Re:GCC should remain small and fast by xski · · Score: 1

    Thank you.

  47. Define properly by tepples · · Score: 1

    Your question is best addressed by simply saying, design your application properly and it won't be an issue.

    Thus the question becomes the following: How should an application written in C++ be designed properly for an environment with no paging?

    1. Re:Define properly by bluefoxlucid · · Score: 1

      The same way you design it properly for an environment with paging. You still OOM without paging, you still OOM without a page file, and you still fail allocations whether or not you get your own virtual memory area rather than a single monolithic shared area.

      What, did you think the swap file made [ if ( ! (a = malloc(sizeof[int] * 1024))) return ENOMEM; ] unnecessary?

    2. Re:Define properly by Anonymous Coward · · Score: 0

      Implement your own operator new() and operator delete()?

    3. Re:Define properly by 21mhz · · Score: 2

      What, did you think the swap file made [ if ( ! (a = malloc(sizeof[int] * 1024))) return ENOMEM; ] unnecessary?

      Swap itself didn't; virtual memory allocation techniques allowing overcommit did.
      It's practically useless to check the result of a malloc on a modern VM-equipped OS, except for very large buffers (where you typically also have an obvious failure path e.g. "screw it, this image is too big"). You program can get OOM-killed after all allocations have succeeded.

      Even in environments with honest-to-god memory allocation, implementing proper OOM safety requires prohibitively thorough testing, where you need to simulate the failure of practically every memory allocation your program might have, and then have a way to ascertain that the failure handling is done correctly. If you want to bring up C++ exceptions as an easy solution, please be aware that each potential throw path also has to be tested individually; look for words "undefined behavior" in the C++ standard to understand why. And please, let's not discuss a hypothetical infallible C++ genius able to wrap everything into 100% correct RAII code; these do not exist in real life.

      --
      My exception safety is -fno-exceptions.
    4. Re:Define properly by bluefoxlucid · · Score: 1

      For the most part, handling a failed allocation (your "malloc() does't fail" argument unfortunately raises problems here...) is a matter of going, "Can't handle this. return ERROR." Then you have to naturally free up the partially allocated resource, if said exists; otherwise the logic to say, "Well that didn't work" is pretty straight forward (nothing allocated, just abort with an error and keep backing out until you get to the function that initiated the resource request anyway).

      Programming isn't voodoo. People say it's "hard" to do certain things but in reality it's just "hard" to design a process. It's easy to do just about anything. It's easy to build the world's tallest skyscraper; some engineer has to figure out how to build the structure to not topple over, though. This is a real concern: think about the compressive strength on cement, on steel, not to mention the flex from just being so damn long, oscillation from the wind... where and how do you need to put beams and tie them together to keep this thing from dropping over?

      Programmers spend a lot of time building a tall tower, then come back complaining it's hard to stop it from toppling when something goes wrong; this is because they considered, for example, memory management as an afterthought, and in the "close" and "free" and "end" and whatever functions they're trying to figure out how they're going to free the right memory, and how they're going to make sure it's actually not in use first. It's a lot of work to design into a process all the state concerns to dictate when an allocated object is and is not in use; however this IS something you can control BY DESIGN. It doesn't have to be mystic voodoo.

    5. Re:Define properly by 21mhz · · Score: 1

      For the most part, handling a failed allocation (your "malloc() does't fail" argument unfortunately raises problems here...) is a matter of going, "Can't handle this. return ERROR." Then you have to naturally free up the partially allocated resource, if said exists; otherwise the logic to say, "Well that didn't work" is pretty straight forward (nothing allocated, just abort with an error and keep backing out until you get to the function that initiated the resource request anyway).

      Right, so all this error handling adds something like 10-30% to the code size and correspondingly increases its complexity, and hence raises the potential for errors (adding new code always does this). And all this is completely useless in all but the most limited execution environments available today. It's no wonder that hardly anybody bothers about checking allocations in application code, outside of "embedded" systems that are equipped with something less than an ARM.

      --
      My exception safety is -fno-exceptions.
    6. Re:Define properly by bluefoxlucid · · Score: 1

      The "potential for errors" typically comes from ... not putting in the correct code to handle exotic events.

      My code can see:

      A) A limited number of expected results.

      B) Anything else

      C) A condition where no result is possible because I can't get the resources.

      Errors seem to keep popping up in the form of not looking for "anything else." The greatest security researcher's tool is the fuzzer.

    7. Re:Define properly by 21mhz · · Score: 1

      The "potential for errors" typically comes from ... not putting in the correct code to handle exotic events.

      There should be emphasis is on "correct". If your code for handling exotic events is not properly tested, it adds to the potential for errors.

      --
      My exception safety is -fno-exceptions.
  48. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    Rewriting large portions of the program just to have something to do is a classic sign of boredom on the part of the developers. Fixing new obscure bugs will keep them busy for years.

  49. Re:GCC should remain small and fast by AvitarX · · Score: 1

    I guess SSDs change this, but I thought compiling was generally IO bound.

    --
    Wow, sent an e-mail as suggested when clicking on "use classic" banner, and got a fast response that addressed my msg
  50. Compiler has more RAM than target by tepples · · Score: 1

    As part of the compiler, use of STL templates is perfectly fine because the compiler will be run on an system with plenty of virtual memory. In general, and especially for an embedded target, the machine where a compiler is run will have far more memory than the machine where the target application is run. This is starting to happen even on the PC, where whole-program optimization on a program the size of Firefox requires a 64-bit machine and a 64-bit operating system.

  51. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    GCC is a large code base with a very long history which predates C++. The move to C++ was done specifically to improve type checking and be able to move from "inheritance in C" to real C++ inheritance. That ignores benefits like being able to refactor the code into classes so it is more clearly organized.

    This was not done out of boredom. It was the recognition that C++ provided strong benefits over C for GCC long term.

  52. Re:too bad GCC is not relevant anymore thanks to L by larry+bagina · · Score: 1

    Apple was contributing to gcc development under the GPL v2 -- ppc optimizations, objective c optimizations, bug fixes, etc.

    --
    Do you even lift?

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

  53. Re:GCC should remain small and fast by ProzacPatient · · Score: 1

    Don't assume everyone is as dim as you.

    Yeah! Not everyone codes in QuickBasic!

  54. C++? by Anonymous Coward · · Score: 4, Funny

    C++? seriously?

    That's it, I'm switching to LLVM!

    1. Re:C++? by willodotcom · · Score: 4, Informative

      C++? seriously?

      That's it, I'm switching to LLVM!

      which is also written in C++

    2. Re:C++? by maxwell+demon · · Score: 1

      C++? seriously?

      That's it, I'm switching to LLVM!

      In which language is LLVM written again?

      --
      The Tao of math: The numbers you can count are not the real numbers.
    3. Re:C++? by IwantToKeepAnon · · Score: 1

      Damit, I was just going to post that. It is so juicy when you can expose the ignorance of the prejudiced.

      --
      "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy
    4. Re:C++? by Anonymous Coward · · Score: 0

      Yeah?! Well then I'll make my own compiler. With hookers and blackjack. On second thought forget the blackjack.

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

      At least they started using C++ from the start with LLVM.

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

      C++? seriously?

      That's it, I'm switching to LLVM!

      which is also written in C++

      Come one, that one had irony tags written all over...

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

      That's why it's funny. All these people saying, "Firefox did what? I'm switching to Chrome" (not even Chromium), are just as stupid. Gee, you don't like how Firefox got rid of the task bar so you are switching, to a browser that doesn't have a task bar. You don't like how Firefox versions are going up to fast, so you are switching to a browser that does it faster! No, it's the fact that plugins don't work properly now!, and that new browser has a plugin ecosystem that sucks so much more, and doesn't have decent equivalents for the very plugins you want most (e.g. AdBlock & NoScript). Tabs on top? The horror! Wait, that's what Chrome does too (and at least in Firefox there is an easy to discover toggle).

      People are often stupid, switching from something they use and like to something else, because of changes. But the thing they switch to has the same faults and flaws!

      Personally, I keep using Firefox because it has a built in RSS feed reader (and the Brief plugin), and a number of plugins that I use regularly, and for various other reasons. Chromium just tends to shit me when I use it.

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

      C++? seriously?

      That's it, I'm switching to LLVM!

      which is also written in C++

      Whoosh.

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

      That's it, I'm switching to LLVM!

      That'a a truly unique pattern of reasoning (given that LLVM is written in C++)

      --
      Not everything that can be measured matters; Not everything that matters can be measured.
    10. Re:C++? by Anonymous Coward · · Score: 0

      Damn it! Then I'm going back to good old Cassette BASIC. LOL!

  55. Re: progress by presidenteloco · · Score: 2, Interesting

    I too would have seen a move from C to C++ as progress...

    in 1989.

    It took me til about 1990 to realize that C++ was a fundamentally broken and overcomplicated attempt at an object oriented programming language. By attempting too much (OO + C backward compatibility) it achieved, to be kind, something other than safety and elegance.

    C++ seems to me like the space shuttle of programming languages; includes a kitchen sink, a tool on board for every purpose, lightning fast, and dangerous as hell.

    So tell me, has 22 years more development managed to fix it?

    --

    Where are we going and why are we in a handbasket?
  56. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 2, Informative

    LLVM was created by freeBSD due to the continual dropping of support for older hardware by the GCC team.

    Wrong!

    The LLVM project started in 2000 at the University of Illinois at Urbana–Champaign, under the direction of Vikram Adve and Chris Lattner. LLVM was originally developed as a research infrastructure to investigate dynamic compilation techniques for static and dynamic programming languages.

  57. Re:GCC should remain small and fast by godrik · · Score: 1

    properly handling C++ template can be a very CPU-bound process unfortunately.

  58. Re:too bad GCC is not relevant anymore thanks to L by schaiba · · Score: 2

    LLVM was created by freeBSD due to the continual dropping of support for older hardware by the GCC team. Another issue they had was the optimizations of the software increased the difficulty of debugging things as the optimizations varied every time they compiled the software. Thus LLVM was created with the goal of binary stability that could be easily debugged and that supported the many older peices of kit that freeBSD runs on instead of being forced to use GCC 1.2/1.5/2.1/2.2/2.3 and such.

    Since when was LLVM created by FreeBSD? o.O

  59. Re: progress by DeathToBill · · Score: 4, Insightful

    No. 22 more years has seen Challenger and Columbia blow up, and we've learnt some lessons about things we should do and things we shouldn't do. Just as the Challenger investigation didn't conclude, "Ban O-rings," nobody has decided to ban parts of C++, either.

    C++ is in some ways like a human language: It has an enormous range of things you can say in it. Some of them are only appropriate in certain situations. Some of them are never appropriate if you want people to take you seriously. Some of them just plain don't make sense.

    So quite a lot of the development over those 22 years has been in the community learning idioms that let you use the power of C++ without hurting yourself.

    --
    Slashdot - News for Nerds, Stuff that Matters, in ISO-8859-1 Has just realised that beta makes this signature redundant
  60. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    There is a way around it: by not being an astonishingly incompetent developer.

    And that's without even getting into features like templates, which only five people in the world understand.

    Don't assume everyone is as dim as you.

    I harbor no thoughts of superiority with C++, but I have used a book called Effective C++: 55 Specific Ways to Improve Your Programs and Designs and get very good results. I haven't benchmarked against equivalent C programs because I am not getting paid to write two versions of the same program. If you have any additional tips for good C++ performance, I would be very grateful.

  61. Re: progress by smittyoneeach · · Score: 4, Informative
    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  62. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    For a compiler? What does a distribution license have to do with a compiler?

    You seem to be treating the GPL like cuties.. Who does believes in GPL cuties? Apple, FreeBSD, 6 year olds, anybody else?

    I like cuties. Especially petite brunette ones. I'm not, however, so hung up on what development tools they use. I'm much more interested in their other attributes!

    As an aside, I don't think GPL has cooties.

  63. Re: progress by maxwell+demon · · Score: 2

    Without C compatibility, there would have been no chance that GCC was ever rewritten in C++. It would have been too much of a task. As is, the C could gradually be amended to be C++ compatible (because C++ is not completely compatible to C) while at the same time continuing normal development, with the only restriction that all new C code must also compile as C++. And now the switch to C++ just means that from now on code that doesn't compile with C will be accepted.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  64. BS, prove it. by Anonymous Coward · · Score: 0

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    Please provide a code example of equivalent code that is faster in C.
    I'd actually like to see a real-ish world example of C code that isn't valid C++ code.

    1. Re:BS, prove it. by Anonymous Coward · · Score: 0

      void foo(int size) {
              int array[size];
      }

    2. Re:BS, prove it. by Anonymous Coward · · Score: 0

      And in what way is that C/C++ slower when compiled as C, than it is when compiled as C++?

    3. Re:BS, prove it. by Anonymous Coward · · Score: 0

      I'd actually like to see a real-ish world example of C code that isn't valid C++ code.

      void foo(int size) {
              int array[size];
      }

      This will valid C code will not compile as C++ code because it's not valid C++ code.

  65. Re:too bad GCC is not relevant anymore thanks to L by Medievalist · · Score: 1

    I assure you your refrigerator temperature thermostat was not programmed in GCC.

    It's unlikely it was programmed at all, unless you call calibrating a sensor "programming".

  66. Re:too bad GCC is not relevant anymore thanks to L by GameboyRMH · · Score: 1

    No, you've been trolled.

    --
    "When information is power, privacy is freedom" - Jah-Wren Ryel
  67. I'm Curious by MBC1977 · · Score: 1

    Does this mean that if decide to use the new GCC, I would be forced to using the GPL v3?

    --
    Regards,

    MBC1977,
    1. Re:I'm Curious by Cyko_01 · · Score: 1

      No. likewise, if you compile with visual studio on windows you can still release your code under any license you wish

    2. Re:I'm Curious by MBC1977 · · Score: 1

      Thanks, much appreciated.

      --
      Regards,

      MBC1977,
  68. Re:GCC should remain small and fast by serviscope_minor · · Score: 1

    don't assume you're as smart as you think you are.

    Who (apart from you) said I claim to be smart.

    Without reference to whether I understand templates or not, I know many people who understand templates well and use them happily.

    The OP is strongly implies he finds templates hard to understand (unless he's claiming to be at least the 5th smartest person in the world). He must be dimmer than all those people I know who do understand templates, then.

    --
    SJW n. One who posts facts.
  69. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    Not entirely true. Apple always did what they should do, contribuing back their patches, etc. It still affected them. Xcode does all sorts of syntax checking on the fly. That's only possible because Clang allows them to link in its parser as a library. That wouldn't be possible to do with GCC (at least for non-open-source IDEs) because it licensed is under the GPL, not LGPL.

  70. When all you have is a type checker by tepples · · Score: 1

    When all one has is a hammer, everything looks like a nail. When all one has is a static type checker, everything looks like a type. For C++ programmers obsessed with type safety, or for people working in a C++-like managed language, the fact that std::hex, std::setfill('0'), std::setw(8), std::dec, and std::endl have definite static types that can be checked at compile time itself makes them superior. But personally, I prefer the std::printf way because the way adds way too much state to a stream.

    1. Re:When all you have is a type checker by shutdown+-p+now · · Score: 1

      I don't know any C++ developer who thinks iostreams to be superior. And I know some folks on the C++ standard committee...

      Boost.Format is a much more reasonably designed formatting library that I'd call idiomatic C++. Iostreams are more like idiotic C++ (this doesn't apply only to formatting, but to the whole design).

  71. Re:GCC should remain small and fast by maxwell+demon · · Score: 1

    I harbor no thoughts of superiority with C++, but I have used a book called Effective C++: 55 Specific Ways to Improve Your Programs and Designs and get very good results. I haven't benchmarked against equivalent C programs because I am not getting paid to write two versions of the same program. If you have any additional tips for good C++ performance, I would be very grateful.

    You might want to read the book More Effective C++ by the same author.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  72. ...different type combinations by tepples · · Score: 2
    I have incorporated your correction about templates into my article. Thank you.

    Programmers can lose track of for how many different type combinations they have instantiated a template, causing code size to balloon. There is a common extension called extern template allowing for explicit instantiation, but it's not in C++98, and not all compilers support it.

    [This] is extremely misleading. Your point of contention is in no way specific to C++ nor templates. It equally applies to any langauge which supports structures and/or classes. That's not C++ nor templates specific issue.

    I still don't understand what you're trying to say about my point about "different type combinations" being wrong. I was referring to the fact that a lot of compilers instantiate templates by duplicating the object code one for each specialization, and you get one specialization for each combination of types, not just for each type.

  73. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0, Insightful

    That may be true but it was because GPL forced them to give back when Apple was still using gcc. Apple doesn't like giving back. They stated as much as their motivation for using llvm. They said that they did not want to have to share their code generation optimizations as their motivation for abandoning gcc.

    If you like parasitic companies (in this case Apple, but there are many) leaching off your work, release with another license, but if you like a healthy community, GPL seems to be the best choice.

    Although this whole thread seems to have veered way OT!

  74. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 1

    Apple started sponsoring LLVM long before the GPLv3 came about.

  75. Mod parent down. by Anonymous Coward · · Score: 0

    You're correct, but you didn't explain why and you're being a dick about it. I don't know why you are +5 informative when you should be -1 flamebait.

  76. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    I could simply say, "haters gonna hate" :) .. however..

    C++ haters by and large have good reasons. They may be ignorant but perhaps that's just because they haven't found the right reasons to give voice to their displeasure. I don't condone bigotry of any sort (even language bigotry), but the whole OOP push of the nineties with C++ at the forefront largely failed to deliver on its promises.

    And I'm sorry, but even very intelligent teams of developers usually create a kind of OO spaghetti with C++. And I would not call them 'astonishingly incompetent'. Just normal. So C++ in my mind has proven itself NOT to be the right language for 'normal' developers.

    Also a lot of the myths around C++ are not questioned enough by the rest of the community. Hence, sites like http://yosefk.com/c++fqa/

    Basically it is assumed that Stroustroup and co. are gods and we're all blasphemers to question their direction.

    And the whole "if you don't like it, don't use it" counterargument doesn't wash either. Many people are forced to use C++ and its esoteric feature set due to circumstances outside of their control. So they learn to hate. And they come here and post. So suck it up.

  77. Re: progress by Anonymous Coward · · Score: 0

    C++: "We only blew up a shuttle or two."

    I don't know if this is the best hill to build your fort on, but as you will ..

  78. Re: Linus must be screaming inside. by Anonymous Coward · · Score: 1

    In other news, Linux Mint forks GCC, calls it Angel Hair Pasta.

  79. Dropping something from cache by tepples · · Score: 1

    If you cannot alloc an object of 20 bytes or so, you've got problems no exception handling will solve.

    One can in theory solve a failure to allocate 20 bytes by discarding a cached 1 MB object, which should allow a few myriad more such allocations.

  80. Re:too bad GCC is not relevant anymore thanks to L by Mister+Liberty · · Score: 1, Insightful

    Stallman is a gentleman with a name.
    You on the other hand are a confused big mouth coward.

  81. Re:too bad GCC is not relevant anymore thanks to L by Guy+Harris · · Score: 1

    That may be true but it was because GPL forced them to give back when Apple was still using gcc. Apple doesn't like giving back. They stated as much as their motivation for using llvm. They said that they did not want to have to share their code generation optimizations as their motivation for abandoning gcc.

    Do you have a citation for that? And what parts of their code generation are missing from the llvmCore directory of their open-source llvm-gcc or clang's CodeGen directory and not contributed back to the LLVM project?

  82. Re:too bad GCC is not relevant anymore thanks to L by beelsebob · · Score: 1

    Interestingly, and not so trollily, this is one fewer reason why clang is not as good as gcc... Clang's website gives a fairly unbiased report of where it's better/worse than gcc, previously, one of only 4 advantages of gcc was that it only needed a C compiler to build it, not a C++ one.

  83. C++ infection... by Anonymous Coward · · Score: 0

    crap.

  84. Any chance of a -Wtypedef-types? by tlambert · · Score: 1

    Any chance of just adding -Wtypedef-types?

    Just having a warning for when you use a typedef type in place of an int or vice versa, or a typedef type of a struct or union whose first element matched the type of the parameter its being used in place of would be a huge improvement.

    At one point in time, I went through the Mac OS X kernel and dealt with the functions that were supposed to be returning an errno_t value mixing in integers and other values not originally in the errno value range, but later in the range. Being able to typedef an enum to an errno_t and then having the compiler squawk when someone interchanged the value with an int would have been incredibly useful, not to mention fixing a metric buttload of HFS bugs that had to be fixed relatively manually instead.

    The way LLVM works, this would be rather trivial (but the request has been outstanding to the Apple LLVM people for 3 years now); I'm told that adding it to gcc would be more difficult because it attempts to dealias things like simple typedef types as early as it can, and the metadata necessary to do warnings (or enforcement, for the -Werror case) is lost before the place it would need to be chacked.

  85. Re:too bad GCC is not relevant anymore thanks to L by beelsebob · · Score: 1

    Where by "invest in", you mean "write and give away their source code under the BSD license"... I'm not sure how that's not "what you should do".

  86. Re:GCC should remain small and fast by Anonymous Coward · · Score: 1

    Why don't you hang out on comp.lang.c++ and comp.std.c++ and see what "understanding templates" really means.

    Most people who say they "understand X" only think they do. Although, usually they understand more than enough to be competent at what they're presently doing.

    The actual language rules are vastly more nuanced than you realize. I'd bank on the fact that you're not an expert, because I know experts (even ones on the standards committees), and they don't say things like "I understand templates". And for a language like C++, with a fscking huge standard document, few to none know every little nuance in and out.

  87. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    Templates are pretty ugly for anything but the common namespace-scoped functions and classes, which in a perfect world, is all you'd use them for. This gets horrible very quickly if they get nested, or, heaven help you, you need to delve into template meta programming.

    Thankfully, C++11 added the constexpr keyword, which greatly reduces the amount of shit you need to involve templates in.

  88. Re:too bad GCC is not relevant anymore thanks to L by beelsebob · · Score: 1

    It stops you from writing tools, like editors, that use the compiler's various parts to do things like syntax highlight, dynamically show errors/warnings, analyse your source code, etc. without GPLv3ing your own code. Which, is rather exactly how "cuties" behave – the infect everything around them.

  89. Re:too bad GCC is not relevant anymore thanks to L by beelsebob · · Score: 1

    However, clang blows the doors off gcc in several different benchmarks... The current generally accepted conclusion is that clang and gcc produce roughly equivalently quick code, though clang produces it significantly faster.

  90. Re:too bad GCC is not relevant anymore thanks to L by beelsebob · · Score: 1, Troll

    That may be true but it was because GPL forced them to give back when Apple was still using gcc. Apple doesn't like giving back.

    Yeh, clearly apple don't like giving back –that's why they wrote clang, and open sourced all of it under the BSD license.

  91. Re:too bad GCC is not relevant anymore thanks to L by jeremyp · · Score: 4, Informative

    The GPL doesn't force you to give back. You need to have a read of it, it only forces you to "give forward".

    Apple has now fully embraced clang/llvm for a couple of reasons: it was legally very difficult to for them to integrate gcc tightly with their IDE (by which I mean they would have to GPL Xcode if they linked directly to gcc); it is technically very difficult to integrate with an IDE - apparently the gcc code base is a complete mess as far as integration with other tools is concerned.

    Clang/LLVM is financed by Apple and it is released under an Open Source licence. Call that parasitic if you like but because of Apple (in part) you now have a clean modern compiler toolchain that's a credible open source alternative to gcc. If nothing else, it means that the gcc dev team now have an incentive to improve their product because they have competition.

    --
    All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
  92. Re: progress by 21mhz · · Score: 2, Interesting

    I too would have seen a move from C to C++ as progress...

    in 1989.

    It took me til about 1990 to realize that C++ was a fundamentally broken and overcomplicated attempt at an object oriented programming language. By attempting too much (OO + C backward compatibility) it achieved, to be kind, something other than safety and elegance.

    Actually if it only had near-compatibility with C and OO, it would have been a very nice and useful language. But then things went south and they added too many overloadable operators, a nightmarish jumble of rules for typecasting/overload resolution, exceptions that can't be implemented properly in modern application software, but add a whole new dimension of concerns that the programmer should always be aware of... Then they topped it all off with hideously overcomplicated templates. The standard libraries mostly have crappy and/or misguided design: practically non-extensible, bloat-inducing iostream, the bloatware generation templates that used to be called STL, and so on.

    So now, real-world projects that use C++ for the useful things it does provide have to maintain coding guidelines to avoid shooting themselves in the foot too often.

    --
    My exception safety is -fno-exceptions.
  93. Re: progress by 21mhz · · Score: 0

    Hah, Boost is a manifestation of all things that are wrong with C++.

    --
    My exception safety is -fno-exceptions.
  94. Re:GCC should remain small and fast by Megane · · Score: 1

    Actually, no. If you just change 'struct' to 'class', and don't use virtual methods or templates, there is absolutely no bloat vs the same C code.

    But to achieve this there is, however, a tradeoff. Which method actually gets used is determined statically at compile time by what you declared it as. If you declare an object pointer CBase* p, and assign a CSubclass* pointer to it, calling p->Foo will always call CBase::Foo and never call CSubclass::Foo. If you can't live with that behavior, then you were probably going to need function pointers anyhow, and for 4 bytes extra per struct you can make as many virtual methods as you want. If you needed more than one, only one vtable is created per class, as opposed to needing 4 bytes per function pointer in every instance of your struct.

    When I first used C++ classes, I actually saved memory because it replaced code that had one messy uber-union that covered all kinds of different memory allocations for various sorts of thingies (and therefore enough for the largest was always allocated), and switch statements everywhere. Afterwards, each thingy got exactly the RAM it needed (from a fixed allocation pool managed by the base class, since this was on a SoC with 64K RAM) and the switch statements were replaced with virtual functions for each thingy. The code was significantly more readable, too.

    But templates are indeed a mess. They cause code bloat because for every object type you want to use with a template, it generates a completely new function just like the others it created before, with the only changes being for the new type. This is in comparison to the Smalltalk style of Objective C, where you can write a single function to work on (effectively) anonymous objects. And the STL assumes you have a heap, which is often not the case in embedded systems programming. The only template I have used is one I created to handle a fixed length array of flag bits, because it made my code a little easier to read.

    --
    #naabhaprzrag, #sverubfr-000, #agi-fcbafberq, negvpyr[pynff*=' negvpyr-ary-'] { qvfcynl: abar !vzcbegnag; }
  95. Re: progress by smittyoneeach · · Score: 3, Insightful

    Which thesis clearly explains why no one uses Boost and it has zero developers, not to mention a dearth of creative ideas.

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  96. Re: progress by Anonymous Coward · · Score: 0

    I suspect you are getting old. Challenger was actually 26 years (and a half) ago...

  97. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    A program written in C++ is going to be slower than an equivalent program written in C

    You know what? I have partially rewritten FFTPACK (originally Fortran, but there is also C and Java implementation) in C++. Result: source code shrieked to about 75% of C version, additionally I have got all precisions for free. Not only that: speed up from 0 - 10 % (depending on radives and N), mostly due to the use forward/backward transform multiplication factor of (+/-1) as "template value" parameter, which results in NOOP in the machine code. My plan is to to go further and shrink the source using radix as a template parameter, which would not only make the code cleaner but allow also recursively inline code for higher non-prime radix (which could again result in some speed increase).

    FFTW is still generally faster (but due to SSE instruction optimizations, not because it is written in C), but FFTPACK is not far behind, for some N (with higher mixed radix of 17, 19, 23) it is actually significantly faster than FFTW (like several times, even with maximum "measured" runtime optimization of FFTW). But FFTW is a few hundred thousand lines (and expensive for commercial use), FFTPACK++ about 4000 lines, public domain. Multi-dimensional another 1000 lines or so. Granted you can "fake" some templates in C using macros but it becomes a mess and lose many template optimizations which c++ will do for you for free.

  98. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    WTF? Templates are resolver at compile time, no overhead at run-time. Granted, templates can contribute to machine-code bloat (if sloppy written), but can also increase speed if you can use template-value parameter which you would normally use as passed variable (such as +/-1, enumerations, type-resolving variables and switches) . In general by using C++ it is much easier to resolve (once for all) many things at compile time (maybe with some machine code increase penalty, but smaller source code) instead of burning cycles at runtime.

  99. An observation of "procedural" coders by GodfatherofSoul · · Score: 3, Interesting

    I've never understood the hostility towards OOP. I've always seen it as nothing more than another great tool to use, but so many posters act as if OOP is some false god brainwashing the masses. My theory is they're taking the act of embracing OOP as synonymous with insulting C.

    Look at the added java.io.PrintStream.printf() method that uses a variable argument list. Someone had to be a special kind of asshole to adulterate a strongly-typed OO-language with that bullshit when the obvious OO solution is an array for a second argument. That's the kind of modification made when someone is making a political point, not a design improvement.

    --
    I swear to God...I swear to God! That is NOT how you treat your human!
    1. Re:An observation of "procedural" coders by dkf · · Score: 1

      Look at the added java.io.PrintStream.printf() method that uses a variable argument list. Someone had to be a special kind of asshole to adulterate a strongly-typed OO-language with that bullshit when the obvious OO solution is an array for a second argument. That's the kind of modification made when someone is making a political point, not a design improvement.

      I can't tell, are you arguing that's a good idea or bad idea? (That Java method takes an array of objects as its second argument; it just effectively annotates the source to say that the compiler should also convert all the arguments after the first into an array, with appropriate value boxing. That gives the effect of varargs while remaining safe, and you can pass an array in that you built yourself if you really want to. But whether you knew that or would have thought that it was good if you did know, I genuinely can't tell.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    2. Re:An observation of "procedural" coders by shutdown+-p+now · · Score: 1

      I don't get your problem with Java printf - is it with varargs in general? Are you complaining that it does not require one to explicitly create an array every time you call it, or what?

      And, most importantly, what the hell does that have to do with procedural vs OO? varargs or lack thereof is completely orthogonal to either one.

    3. Re:An observation of "procedural" coders by Anonymous Coward · · Score: 0

      Look at the added java.io.PrintStream.printf() method that uses a variable argument list. Someone had to be a special kind of asshole to adulterate a strongly-typed OO-language with that bullshit when the obvious OO solution is an array for a second argument. That's the kind of modification made when someone is making a political point, not a design improvement.

      Say wha huh? Variable arguments *are* arrays in Java. You're complaining about a syntactic shortcut that in no way compromises OO design - at least not anymore than if the method explicitly took Object[].

    4. Re:An observation of "procedural" coders by Anonymous Coward · · Score: 0

      I've never understood the hostility towards OOP. I've always seen it as nothing more than another great tool to use, but so many posters act as if OOP is some false god brainwashing the masses. My theory is they're taking the act of embracing OOP as synonymous with insulting C.

      There is a huge difference between being hostile to OOP and being hostile to C++ and Java.
      I like OOP a lot, it really helps to structure and maintain your code. I still prefer to use OO in C or assembler. I simply cannot stand languages like C++ and Java. It seems to me as if the languages are designed to hide functionality from the programmer. For some reason some programmers think that "readable" code is when you write as many abstraction levels and help functions that it's pretty much impossible to figure out if code is efficient or if it is going to deadlock on you if you as much as look at it.
      My hostility is definitely not aimed at OOP. I'm very sure that I just have a hostility towards a small set of programming languages. (Just be glad that TFA didn't mention PERL.)

    5. Re:An observation of "procedural" coders by Anonymous Coward · · Score: 0

      Or they had to be a computer scientist.

      A variable argument list can be passed on the stack, is far more efficient than allocating a brand new array, and in any event doesn't even violate any OOP principles. The variable list of arguments are still type-safe objects.

      You misunderstand the beauty of printf(). It's a tiny, non-turing complete language which provides a convenient and concise language to format an output sequence. printf() is a computing abstraction. Some of the type constraints can't be determined at run-time, but that's hardly exceptional. If you abstain from implementing domain specific languages or state machines in Java because you're afraid of violating OOP principles or static type safety, then you have far more serious problems as an engineer.

    6. Re:An observation of "procedural" coders by Anonymous Coward · · Score: 0

      Variable argument lists in Java are implemented using arrays. If you really want to you could allocate an Object[] and pass that as the second argument to PrintStream.printf and it will work fine. The variable argument list just saves a bit of typing at each method call.

    7. Re:An observation of "procedural" coders by Deorus · · Score: 0

      I still prefer to use OO in C or assembler.

      The most agreed-on component of OOP is self-awareness, i.e.: objects are aware of themselves and the language provides a this / self pointer that always refers to the instance a function7 was called as. If the language does not provide such a facility, then it's not OOP by any stretch of reality. C does not provide such a facility, and neither does assembly on any architecture that I'm aware of, including intermediate languages such as Java's bytecode (which actually does support other OOP concepts such as polymorphism).

      It seems to me as if the languages are designed to hide functionality from the programmer.

      Here you demonstrate total lack of knowledge of C++. C++ does not hide anything from you, bottom line it's as low level as C. It does, however, provide the ability to enforce encapsulation, which is one of the pillars of all Simula-style OOP languages, but so does C with its static keyword...

      For some reason some programmers think that "readable" code is when you write as many abstraction levels and help functions that it's pretty much impossible to figure out if code is efficient or if it is going to deadlock on you if you as much as look at it.

      And what does any of that have to do with the language at all? If you use someone else's libraries you're bound to have the same problems in C, too...

      My hostility is definitely not aimed at OOP. I'm very sure that I just have a hostility towards a small set of programming languages. (Just be glad that TFA didn't mention PERL.)

      It's Perl, not PERL, it's not an acronym, you idiot! I'm pretty sure your hate is entirely motivated by your ignorance and fear of the unknown as perfectly demonstrated by your post! You should be ashamed of calling yourself a software engineer!

    8. Re:An observation of "procedural" coders by Anonymous Coward · · Score: 0

      I remember when COBOL programmers were considered a null in OOP and could not even learn it. I jumped from most basic basic straight into C++ and am glad for it! Did not even touch C as such (pun?). So I found that the mind frameset is so different between procedural and OOP that procedural types will always complain against OOP, while OOP types... well, you just start programming, if you know what I mean. It still feels funny with programs that start in a main() procedure rather than defining a standard class derivation constructor (with argument passing support, etc.).

    9. Re:An observation of "procedural" coders by benhattman · · Score: 1

      The biggest problem with OOP is that a lot of college grads from the last 15 years were raised into as being the only proper paradigm. Many of those people insist on designing code that is functional in nature or procedural in nature as objects. Basically, if you give people a tool they will abuse it.

      I say this as someone in the dead center of that 15 year window.

  100. Re: progress by Greyfox · · Score: 3, Interesting
    I hadn't really looked at it much through the course of my career -- most of my employers wanted C or Java, not C++. Having only recently started with it, I'm finding it to be about as sharp a weapon as C, but with the ability to be far more type safe. It really isn't that difficult to get a grasp on it. You just need to understand its pass-by rules, which are moderately more complex than Java's. You also need to be able to understand the STL and use it effectively. You also need some object oriented design experience if you're doing your own design work.

    The third party libraries for it are pretty nice these days, too. I'd rather do threading in C++ with boost::thread than in Java. I've found boost::regex and boost::program_options to be a joy to work with as well. Eigen is also very nice if you need a math library.

    Overall I've been quite enjoying working with it. It's not nearly as intimidating as it first appears, and the stuff you really need to know about it is pretty simple and easy to learn.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  101. Re:too bad GCC is not relevant anymore thanks to L by lindi · · Score: 1

    LLVM and clang are library oriented. An IDE can reason a lot about the code using the API, much more than it could ever do if it just fork()'d and exec()'d "gcc" and parsed its warnings and error messages.

  102. STL... meh by ElusiveJoe · · Score: 1, Interesting

    STL is ugly. Even the Qt framework provides a much cleaner and consistent alternative, than this "standard" library.

    STL is also not good for any performance bound programs, not good at all. You can easily write code that looks nice, but silently kills your performance.

  103. Portability? by ElusiveJoe · · Score: 1

    What about portability? C++ is much worse in it, the standard has too many vague or missing parts, particularly templates.

    1. Re:Portability? by Anonymous Coward · · Score: 0

      What do you mean? C++ portability issues lie in implementation details which cause compatibility issues when using different compilers (or versions) to compile different parts of the same program (eg throwing an exception from a part of the code compiled with a certain compiler to a different part of the code compiled with another compiler is a recipe for trouble). There is no portability issues if compiling the whole program with one compiler, if avoiding implementation-defined behaviour. In fact, the reason the standard is vague about implementation is precisely so that C++ will as portable as possible...

  104. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    I used to be more polite to ignorant C++ haters. But I've lost patience.

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    There is a way around it: by not being an astonishingly incompetent developer.

    Doesn't help. STL arrays are allocated on the heap, and that's a quite slower and more wasteful allocation form than on the stack. Sure, you can use C arrays, but guess what: out go type safety and STL algorithms and C++ idioms.

    If you are writing efficient numerical code dealing with multidimensional arrays, chances are that you are working with a highly sophisticated library incompatible with the array representation of any other library, or having rather slow code, or using extern "FORTRAN", or having totally incomprehensible code with manual index arithmetic.

    And don't get me started on the type conversion lattices.

  105. Re:too bad GCC is not relevant anymore thanks to L by schroedingers_hat · · Score: 1

    most-often executed output code on earth', then yes, I guess you're right.

    Don't forget mars, too. Can't seem to find the source, but pretty sure I read that nasa uses gcc.

  106. Re:oh nooos by chronokitsune3233 · · Score: 1

    I think you meant "standardized" rather than "widely supported." Objective-C can be considerably faster than C++, and the GNU compiler collection (GCC) does provide an implementation of Objective-C. I'd rather use that than C++. However, C++ is standardized by ISO/IEC whereas Objective-C has no comparable formal standard other than the documentation available from Apple. In addition, Objective-C technically has no formal libraries whereas C++ has , , etc. Simply put, C++ is a better choice if moving to an OOP language, even if the features used in the GCC source cause it to build and run more slowly.

    --
    I have been a captive in America my entire life. Everybody and everything uses customary units instead of metric.
  107. The best use of classes is... by iplayfast · · Score: 1

    The best use of classes is to organize code. So from the summary I would say that it is a smart move to be able to organize the code in a way that makes it more readable. You don't have to use all the ugly parts of C++ in order to get some benefit from it. Just stay away from boost/templates and it will be fine.

  108. Re:too bad GCC is not relevant anymore thanks to L by geminidomino · · Score: 1

    In fact that is has no effect on the end user is one of the topmost clause of the GPLs.

    Not that that fact does much to stop the silly people who develop GPL software for windows from using it as a Click-Through EULA on the installers...

  109. Re:too bad GCC is not relevant anymore thanks to L by Darinbob · · Score: 1

    I think most 32-bit embedded still use GCC if they're not x86 based (and really very few are x86). 8 and 16 bit CPUs are more varied though GCC still holds its own. GCC is the most common C compiler ported to new architectures. Sure you can get the chip maker's preferred compiler but too many groups don't have the budget to pay for those especially when they come with a per-seat license. For one company we switched away from a commercial compiler with a good reputation to GCC and got faster and smaller code with amazingly faster compile times (though it was C++ and not C).

    If things are in assembler then GNU assembler is just as good as the commercial ones, though it may tweak "official" assembler syntax slightly.

  110. Re: progress by friedmud · · Score: 1

    "So now, real-world projects that use C++ for the useful things it does provide have to maintain coding guidelines to avoid shooting themselves in the foot too often."

    How is that not the case for _any_ modern language? Anyone write terrible code in any language. I've seen some Python that made me want to rip my eyeballs out (used tons of esoteric functionality... coupled with a design that made me question the person's sanity).

    Coding guidelines are a good idea no matter the language. Keep everything consistent and make sure that the code remains maintainable into the future...

  111. Re:too bad GCC is not relevant anymore thanks to L by Darinbob · · Score: 3, Informative

    And the AVR I have used used a mix of GCC and GNU assembler. I think someone somewhere had an official commercial compiler for it but that doesn't help if it's not licensed for anyone in the company to use.

    I have actually seen cases where companies license one commercial compiler for use in production builds while all the developers use GCC, out of concerns that the commercial compiler is more efficient while being too expensive to license more broadly. Over time there's pressure to dump the commercial compiler because it tends to be difficult to debug when the devs don't have access to the production compoiler, and because it turns out the expensive compiler doesn't really generate more efficient code.

  112. Real men program in C by boddhisatva · · Score: 1

    "C++ is a horrible language." - Linus Torvalds

    1. Re:Real men program in C by tlambert · · Score: 1

      "I still maintain the point that designing a monolithic kernel in 1991 is a fundamental error. Be thankful you are not my student. You would not get a high grade for such a design :-)" - Andy Tanenbaum

      Bjarne Stroustrup himself, in the chapter 18 of his book The Design and Evolution of C++, frowns on the use of preprocessor and wishes to eliminate it completely.

      So Stroustrup complains about Kernighan and Ritchie's work, Torvalds complains about Stroustrup's work, and Tanenbaum complains about Torvalds work...

      It's the circle of life: everyone who has ever written a line of code has someone who will complain about that line.

  113. Re: progress by Darinbob · · Score: 1

    Current C++ style has abandoned any pretence of object oriented programming and the zealots will hammer on you until you adopt a bloated generics based programming style.

    As for GCC I have noticed a very large decrease in compile times when switching from gcc to g++ on the exact same file, as in an order of ten perhaps. Now that's not such a big deal if it's just gcc being compiled itself by g++, as most people don't care how long it takes a third party to compile their compiler. But people who build their own cross compilers I'm sure will notice the long wait for the build to finish.

  114. Shared Memory ?? by frankgerlach11 · · Score: 0

    google it.

  115. Re: progress by Darinbob · · Score: 1

    In those 22 years a lot of up and coming kids have decided that all programming should be done in web browsers or with scripting languages.

    Of course it's not doom for traditional programmers because someone still has to write the efficient code to implement the scripting languages and their runtime system. (I could be wrong, some professionals who should know better still think reference counting for GC in a VM is a good idea)

  116. Re: progress by 21mhz · · Score: 1

    How is that not the case for _any_ modern language? Anyone write terrible code in any language. I've seen some Python that made me want to rip my eyeballs out (used tons of esoteric functionality... coupled with a design that made me question the person's sanity).

    Coding guidelines are a good idea no matter the language. Keep everything consistent and make sure that the code remains maintainable into the future...

    That's true, but I haven't seen guidelines for Python forbidding whole language features for being broken by design. With C++, it's a sad necessity.

    --
    My exception safety is -fno-exceptions.
  117. c++ ? by Anonymous Coward · · Score: 0

    Since yesterday, I realized that `struct {...}` IS also a c++ class :-)
    So I've started to re-write all of my source files with `struct` instead of `class` This way I am positionning my self more as in-between an old-geiser C programmer with a taste of the new C++ -- because shit is becoming so obscure and SHIT when used outside of the STL !!!!!!!

     

    1. Re:c++ ? by Deorus · · Score: 0

      First, what's the STL?

      Second, a struct and a class differ in that all class members are private by default whereas struct members are public. While you can obviously be explicit about making struct members private or protected (just like you can be explicit about making class members public or protected), it's best to have encapsulation turned on and hiding your internals by default than having them exposed by having encapsulation turned off.

  118. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    TI MSP430 too...

  119. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    Hence, sites like http://yosefk.com/c++fqa/

    Many of the assertions on Yossi Kreinen's C++FQA page have been soundly refuted, and many more are simply opinions (or, less kindly, rants). As with any language, there are valid criticisms of C++; the FQA page is not the best place to go looking for reasonable discussions on such matters.

    - T

  120. Re: progress by shutdown+-p+now · · Score: 1

    C++ seems to me like the space shuttle of programming languages; includes a kitchen sink, a tool on board for every purpose, lightning fast, and dangerous as hell.

    Well, given that C is also lightning fast and dangerous as hell, all C++ does is bring kitchen sink into the equation. So long as it's a lightning fast kitchen sink, I don't see a problem with that.

    Everything that C does, C++ does as well, at least as good, and often better. That's why it's so popular, regardless of being inelegant etc.

  121. Re: progress by luis_a_espinal · · Score: 2

    "So now, real-world projects that use C++ for the useful things it does provide have to maintain coding guidelines to avoid shooting themselves in the foot too often."

    How is that not the case for _any_ modern language? Anyone write terrible code in any language. I've seen some Python that made me want to rip my eyeballs out (used tons of esoteric functionality... coupled with a design that made me question the person's sanity).

    Coding guidelines are a good idea no matter the language. Keep everything consistent and make sure that the code remains maintainable into the future...

    You are missing the point. Most languages, if not all, have coding guidelines, but compare guidelines for, say, Java, Python, or even C, with existing coding guidelines in C++. You'll see the difference in how much the later cuts through what is available in C++.

    Pretty much most C++ coding guidelines (in particular for systems and mission-critical development) cut away templates, STL, i/o streams and exceptions. Boost and RTTI are certainly the most banned of things.

    So you end up with a C-like language with native support for object-orientation, which is really not a bad thing. If you are lucky, you might get some limited usage of templates (limited in the sense that you have to demonstrate, but really demonstrate your usage will not *explode* into code bloat via template hoisting or what not). A few of the most used STL template classes, string, auto_ptr, map and list are typically permitted. In many cases, the later three are restricted to instances parameterized to void* or to references to a very restricted, audited set of subclasses.

    The lack of exceptions forces a design based on error codes. The later is really not a great choice, but the semantics are clear, far clearer than exceptions as implemented in C++. And that's why sometimes people, out of painful experience, end up choosing C with simulated inheritance as a safer, more cost effective alternative.

    One typical counter-argument is that people aren't intelligent enough to use C++ safe. Maybe so, but mental effort should be saved to harness a language most effectively in solving problems in a particular domain, not on knowing how not to blow your toes to pieces.

  122. Re:GCC should remain small and fast by Aidtopia · · Score: 1

    STL arrays are allocated on the heap, and that's a quite slower and more wasteful allocation form than on the stack.

    Actually, STL arrays (as in std::array) can be allocated on the stack. They have no overhead.

    It seems you're referring to STL vectors (as in std::vector), which is an implementation of a dynamically-sized container, so, yes, it uses the heap—as does every other dynamic container I know of. That neither makes it significantly slower nor more wasteful.

    Sure, you can use C arrays, but guess what: out go type safety and STL algorithms and C++ idioms.

    False on all counts. C arrays can be used with type safety, with STL algorithms, and with C++ idioms.

  123. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 2, Interesting

    apparently the gcc code base is a complete mess as far as integration with other tools is concerned

    Lots of that was self-inflicted. GCC maintainers did not permit attempts to refactor GCC into smaller reusable component libraries, or import / export abstract syntax tree (AST) data. Granted, these things were difficult due to GCC's legacy codebase problems, but you couldn't even try. Your patches would be rejected.

    It was pure Richard Stallman tinfoil hat paranoia. RMS believes that if you make GCC too modular, especially with interfaces that can't propagate GPL virality, it will inevitably become a wedge used to destroy GCC. You see, people could then write non-free programs to extend GCC in useful ways. And under RMS-ism, you can't have that. It's better for holy free software purists to live in hair shirts than to permit changes which might theoretically allow outsiders to tempt them with evil. So RMS used his influence with the FSF and GCC to block attempts to move GCC in that direction.

    There was also a lot of provincialism. I believe C++ used to be unthinkable, but that tune may have changed due to the success of clang / LLVM, which use C++ features to good effect. GCC's ancient crufty internals have become a huge barrier to progress, and this sounds a bit like belated recognition of it. (They have to be worried about contributor mindshare going to LLVM family projects merely because they're so much easier to work on.)

    Clang/LLVM is financed by Apple and it is released under an Open Source licence. Call that parasitic if you like but because of Apple (in part) you now have a clean modern compiler toolchain that's a credible open source alternative to gcc. If nothing else, it means that the gcc dev team now have an incentive to improve their product because they have competition.

    Apple was very frustrated with the state of affairs I described above. They (and many other non-purist GCC contributors from the commercial sector) wanted to modernize GCC to make it more competitive with closed source compilers, but the FSF literally wouldn't let them. See also: the egcs fork, which also had its origins in FSF small-mindedness. However, after egcs effectively won that battle, the FSF was able to bring GCC back under its control. If Apple ever considered a serious attempt to fork GCC, no doubt that outcome played a role in deciding against it.

    Ironically, the result is that now we have a complete, high quality alternative to GCC, it's not burdened by a horrible internal design preserved in amber by misguided distrust of outsiders, it's licensed more permissively, it's structured exactly the way RMS feared, it's not rigidly controlled by the FSF (which requires that everything contributed to GCC have copyright assigned to the FSF), deep-pocketed commercial GCC contributors are migrating to it because it's run by sane people, and nobody is using it to force proprietary software on the free software community.

  124. Re:GCC should remain small and fast by shutdown+-p+now · · Score: 3, Informative

    Doesn't help. STL arrays are allocated on the heap, and that's a quite slower and more wasteful allocation form than on the stack.

    What is an "STL array"? If you mean std::array, then no, it's allocated on the stack. If you mean std::vector, then that's a dynamically resizable array, and an analogous data structure written in C would still be heap-allocated - you'd just have to do malloc/realloc/free yourself.

    Sure, you can use C arrays, but guess what: out go type safety and STL algorithms and C++ idioms.

    Again, wrong. Since raw pointers are iterators, you can perfectly well use STL algorithms and other C++ idioms with C arrays. In C++11 it's even easier now that std::begin and std::end are defined as global functions, and overloaded for arrays, so you don't need to much around with pointers at all. Type safety is still there as well, since C arrays are typed.

  125. Re:GCC should remain small and fast by shutdown+-p+now · · Score: 1

    But templates are indeed a mess. They cause code bloat because for every object type you want to use with a template, it generates a completely new function just like the others it created before, with the only changes being for the new type. This is in comparison to the Smalltalk style of Objective C, where you can write a single function to work on (effectively) anonymous objects.

    The Smalltalk/Obj-C/Java approach, on the other hand, has a significant perf hit, because of that extra level of pointer indirection, and the requirement to shove everything onto the heap to get an object reference to it. In this case it's a trade-off between code size (a single implementation working via opaque pointers) and speed (specialized implementations, each working directly on values of the specified type). C++ chooses speed. If you want size, you can still do it without templates, same way as you do it in Obj-C - the standard qsort function shows how.

  126. Re:too bad GCC is not relevant anymore thanks to L by Anonymous Coward · · Score: 0

    Gee, I guess shouldn't be using mspgcc with my MSP430's then, boy dp I feel dumb not using Keil.

  127. Re: progress by brantondaveperson · · Score: 1

    Yes, but on slashdot everyone appears terrified of it.

  128. Re:too bad GCC is not relevant anymore thanks to L by cheesybagel · · Score: 2

    Actually the exceptions that allow you to build non-GPL programs aren't necessary. Otherwise all art you produce with GIMP or text you write with Emacs would be GPLed as well. Stallman just added them to stop the FUD against GCC.

  129. Re: progress by cheesybagel · · Score: 1

    Boost has no concept of modularity. Try to distribute just a piece of it. It also gets regularly broken by compiler changes because they like to use bleeding edge constructs. Plus some of the functions are slow as heck because it can contain no assembly. Whereas say memcpy in the C standard library is usually optimized with assembly code. Try reading the includes in Linux for example.

  130. Re: progress by cheesybagel · · Score: 1

    The best implementation of exceptions I have seen is the one in Python. Exception just work. In Java you have to keep writing more and more handling code and the compiler squeals if you don't catch every single little dinky exception. In C++ the exception handling code often causes a SIGSEGV and you wonder what the heck happened in the first place. At least with C you know you don't have exceptions.

  131. Who cares? Long live LLVM/Clang by tyrione · · Score: 0

    I could give a rat's a$$ about GCC. They blew it and will be replaced by LLVM/Clang industry-wide, sooner rather than later on.

  132. Re:too bad GCC is not relevant anymore thanks to L by tyrione · · Score: 1

    Irrelevant? Not quite. For your particular use, maybe. But most Linux distros are still built using GCC, and most embedded platforms provide a GCC-based toolchain. So if, by 'irrelevant', you actually mean, 'the compiler with the most-often executed output code on earth', then yes, I guess you're right.

    The fact that Debian is making it's packages LLVM/Clang ready to build against, especially for the obvious FreeBSD branch it should be abundantly clear that they are aware of the architectural advantages of LLVM/Clang/LLDB/Compiler-RT, etc.

  133. Re:too bad GCC is not relevant anymore thanks to L by cheesybagel · · Score: 1

    I try to compile my C++ code with clang every single time a new Ubuntu release is launched. Clang is consistently much slower than GCC for me. Sure it compiles quickly with color messages, but the resulting code is slow as heck.

  134. Re: progress by Anonymous Coward · · Score: 0

    I've never had and of the problems you describe.

  135. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    I used to be more polite to ignorant C++ haters. But I've lost patience.

    A program written in C++ is going to be slower than an equivalent program written in C, no way around it.

    There is a way around it: by not being an astonishingly incompetent developer.

    Give me one example of a program written in C++ where less than half of the compiled result is bloat.

  136. Re: progress by smittyoneeach · · Score: 1

    No, it's a straight-up troll.

    --
    Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
  137. Re:too bad GCC is not relevant anymore thanks to L by Jonner · · Score: 1

    While the GPLv3 was the reason Apple suddenly invested in clang (which just happens to ride on llvm), it has little effect on any companies that do what they should do.

    The GPL in general was the reason Apple invested in LLVM and Clang. Jobs has been hostile to Copyleft ever since NeXT was not allowed to get away with violating the GPL with their Objective C frontend. I'm still somewhat surprised that Apple continues to release CUPS under the GPL. Of course the difference there is that they hold the copyright so they can make any part of it proprietary any time they want. They have done so for OSX-specific parts.

  138. Re:too bad GCC is not relevant anymore thanks to L by TwinkieStix · · Score: 1

    I believe that gcc includes libraries that link to your code to make it compile. The analogy to GIMP would hold if gimp shipped with GPL clip art that, if used in your artwork, would force your artwork to be GPL. These libraries (the clip art) need to ship as LGPL / BSD / CC/ or something less copy left to let you use them and still keep your code non-GPL.

  139. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    I used to be more polite to ignorant C++ haters. But I've lost patience.

    Well then you've lost the argument before you've started. No one ever convinced anyone of anything by abusing them.

  140. p to the motherfucking ython bitches by Anonymous Coward · · Score: 0

    They should rewrite the thing in python. /ducks

  141. Re: progress by DuckDodgers · · Score: 2

    C++ is awesomely powerful, incredibly fast and resource efficient, and between new high performance applications and existing codebases it will continue to be used for decades.

    However, it also has a beastly learning curve and lots of corner cases, and while its execution speed is wonderful it's so complex that compilation times for non-trivial applications are slower than equivalent feature (but slower execution) applications written in most other languages. If you really need performance that only C++ can provide, use C++. If you have a team of brilliant C++ developers, use C++.

    If you don't have either of those needs, you owe it to yourself to investigate alternatives.

    I'm sure the people working on GCC are C++ experts, so I think that's a place where C++ is an optimal or nearly optimal choice.

  142. Re: progress by DuckDodgers · · Score: 2

    The Java community is working around some of the design flaws in the language related to exceptions. As you probably know, RuntimeExceptions don't have to be declared or explicitly caught with try/catch, unless the developer wants to catch them. So I've seen tons of code in different open source libraries that wraps the core Java libraries with code that does try { doSomethingWithCoreJavaLibrary(); } catch (Exception ex) { throw new RuntimeException(ex); }

    Java keeps evolving, they keep adding new features and offering simpler syntax for common tasks. Maybe by version 11 or 12 it will be a language that won't make experienced Python, Ruby, Perl, and Lisp developers get sick to their stomach just reading it. ;)

  143. Re: progress by afidel · · Score: 1

    Ah, I see you're a conservative software engineer.

    --
    There are 4 boxes to use in the defense of liberty: soap, ballot, jury, ammo. Use in that order. Starting now.
  144. Re:GCC should remain small and fast by AvitarX · · Score: 1

    Yes, but GGGP said that using C++ would slow down GCC, I said that I thought compiling was IO limited, then GP said template usage is CPU intense (implying that using C++ within gcc could actually slow down a compile).

    --
    Wow, sent an e-mail as suggested when clicking on "use classic" banner, and got a fast response that addressed my msg
  145. Re: progress by 21mhz · · Score: 1

    "Which thesis clearly explains why Boost has been used in approximately zero projects of consequence"
    FTFY

    not to mention a dearth of creative ideas.

    Just because one has a creative idea, doesn't mean it should be used in code serving real-world needs. Especially if the code in question is meant to be reusable in a shared library, with a stable ABI and all.

    --
    My exception safety is -fno-exceptions.
  146. Re:too bad GCC is not relevant anymore thanks to L by tyrione · · Score: 1

    NeXT bought sole rights to Objective-C from Stepstone long before the Apple merger. They also hold all rights to Objective-C and if they wanted to be vindictive they could cancel its inclusion into GCC, but the don't. Instead, they chose to produce a solution for the entire toolchain in LLVM/Clang. LLVM/Clang has come a long way in a very short time span since Apple invested in it giving us all a choice to leave GCC--a very welcome choice.

  147. Re:too bad GCC is not relevant anymore thanks to L by Jonner · · Score: 1

    NeXT bought sole rights to Objective-C from Stepstone long before the Apple merger. They also hold all rights to Objective-C and if they wanted to be vindictive they could cancel its inclusion into GCC, but the don't. Instead, they chose to produce a solution for the entire toolchain in LLVM/Clang. LLVM/Clang has come a long way in a very short time span since Apple invested in it giving us all a choice to leave GCC--a very welcome choice.

    Neither NeXT, Apple nor anyone else can "cancel" a Free Software release whether they hold the copyrights or not. Copyright holders can stop making new releases, but they can't take away code already released under the GPL. NeXT did release their extensions to GCC under the GPL for many years because they were depending on the large amount of work that others had put into it. They clearly valued GCC enough to relase their code under the GPL even though they would have preferred a different license. Just as NeXT benefited from GCC, others continue to benefit from NeXT's and Apple's contributions to it. This is a clear success for Copyleft because everyone benefited.

    Now that Apple and others have put a large amount of work in LLVM-based compilers, they may be able to end their reliance on GCC, but it took many years and man-hours of work. Although there are plenty of good technical reasons for LLVM, I'm sure that not being required to share enhancements was a major motivation for Apple. That's not to say LLVM projects are a waste of time. It certainly is good that they exist and there is now more competition in the Free compiler space. Hopefully, LLVM projects will remain healthy despite their licenses. Governance and other aspects of the community are just as important or more so than license and there certainly are plenty of examples of permissively-licensed projects used and contributed to by many which thrive such as Apache and PostgreSQL.

  148. But what about gfortran? by Anonymous Coward · · Score: 0

    So will gfortran convert in C++ now?

  149. Re:too bad GCC is not relevant anymore thanks to L by mbkennel · · Score: 1

    "I'm sure that not being required to share enhancements was a major motivation for Apple."

    Probably not but they might have wanted the option. It's not hard to imagine some case where sharing development code might have given competitors information about upcoming Apple hardware designs, and Apple is as freakishly paranoid about that as the FSF is about people using unfree software.

    The legal means that GCC used to prohibit various technical circumventions which the FSF believed would benefit "not-free" software, also prohibited a modular design which Apple wanted to, and then later exploited for significant benefit.

    The FSF thought that ideology was more important than technical flexibility and capability. As a result, the experience of developing with gcc is about the same as 1989, whereas XCode can do many more things, because compiling programs to machine code is not the alpha and omega of software development tools.

  150. Re: progress by 21mhz · · Score: 1

    The Java community is working around some of the design flaws in the language related to exceptions. As you probably know, RuntimeExceptions don't have to be declared or explicitly caught with try/catch, unless the developer wants to catch them. So I've seen tons of code in different open source libraries that wraps the core Java libraries with code that does try { doSomethingWithCoreJavaLibrary(); } catch (Exception ex) { throw new RuntimeException(ex); }

    It's actually a subject of a holy war between two camps in software design. The "conservatives", should I say, hold that exception types are an important part of an API, and checked exceptions should be exhaustively handled accordingly to their types, possibly by being rethrown as exceptions classified in a higher-level functional domain. Unfortunately, this approach is enforced as applies to the standard libraries, to great inconvenience of the "liberals".

    A more balanced approach would have been to allow exception specifications in method signatures, but not to mandate the handling violations to be fatal: the compiler can still generate warnings, and the developers can decide how seriously do they want to treat them.

    --
    My exception safety is -fno-exceptions.
  151. Re:too bad GCC is not relevant anymore thanks to L by Jonner · · Score: 1

    "I'm sure that not being required to share enhancements was a major motivation for Apple."

    Probably not but they might have wanted the option. It's not hard to imagine some case where sharing development code might have given competitors information about upcoming Apple hardware designs, and Apple is as freakishly paranoid about that as the FSF is about people using unfree software.

    I'm hardly the only one to notice Apple's preference for permissively licensed software:
    "GCC currently handles all those phases for compiling code within Xcode, Apple's Mac OS X IDE (Integrated Development Environment). However, there are some drawbacks to using GCC. One is that it is delivered under the GPL, which means Apple can't integrate it directly into Xcode without making its IDE GPL as well. Apple prefers BSD/MIT style open source licensees, where there is no limitation upon extending open projects as part of larger proprietary products."

    The legal means that GCC used to prohibit various technical circumventions which the FSF believed would benefit "not-free" software, also prohibited a modular design which Apple wanted to, and then later exploited for significant benefit.

    The FSF thought that ideology was more important than technical flexibility and capability. As a result, the experience of developing with gcc is about the same as 1989, whereas XCode can do many more things, because compiling programs to machine code is not the alpha and omega of software development tools.

    The FSF has always put software freedom as their top priority. The reason we even know who they are is that they produced useful software based on their principles. GCC is certainly an old project that could benefit from newer approaches. Its limitations have much more to do with it being old than anyone's politics. That's why competition from LLVM is good for all of us, whether we use LLVM or GCC, which is being pushed to advance by LLVM. As interesting as LLVM is, far more platforms and developers still depend on GCC so the FSF's dedication to their principles continues to benefit everyone as well.

  152. Re: progress by Anonymous Coward · · Score: 0

    (XP searches would go dead into my boost zip file, so I erased eventually)

  153. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    And Slashdot is?

    You say they've been soundly refuted. Where? Links please.

    If you can convince me that template meta-programming is a great idea, then sir, you have won the debate. Proceed ;)

  154. Re:oh nooos by petermgreen · · Score: 1

    Objective-C can be considerably faster than C++,

    I'd like to see a source for that claim, the wikipedia article implies (but doesn't explicitly state) the opposite.

    --
    note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
  155. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    And Slashdot is?

    Only occasionally. The signal-to-noise ratio is awful, but cruising the C++ language stories (and sometimes Java and so on) at 4 or 5 sometimes leads to worthwhile posts.

    You say they've been soundly refuted. Where? Links please.

    Google is your friend; start with comp.lang.c++.moderated and go from there.

    If you can convince me that template meta-programming is a great idea, then sir, you have won the debate.

    Well, I'm not an evangelist, just someone who prefers opinions which are not emotionally based. C++ templates offer a bit more capability overall than C# or Java generics, but arguably less than LISP macros; admittedly, the syntax is ugly. I'd suggest reading Eisenecker & Czarnecki's Generative Programming (if you haven't already), to determine whether you consider generic programming to be useful, then decide whether the C++ approach is palatable to you. I don't know that I would describe C++ template meta-programming as "great" - it's just another tool to be used when appropriate. If it gets overused or inappropriately used by some programmers, that's not the fault of the language, but rather of the programmers, or perhaps of some of the tutorials which have been available.

    We can find some definite problems, or at least a lack of specificity, in the C++98 standard with respect to templates and name resolution. For example, check out 9.2.2 and 9.3.5 in Vandevoorde and Josuttis's C++ Templates. AIUI, these were to have been corrected in C++11, but I haven't yet verified that for myself. I'm sure we could agree that no language is perfect. However, I believe we aren't well served by inaccurate, misdirected, and hyperbolic arguments; I hope we could agree on that, also. Unfortunately, the valid or defensible points in Yossi's FQA are buried in the morass, and perhaps this is where we won't agree.

    - T

  156. Re:too bad GCC is not relevant anymore thanks to L by benhattman · · Score: 1

    I assure you your refrigerator temperature thermostat was not programmed in GCC.

    God I hope not. I don't mind if it's compiled in GCC, but if it's programmed in GCC I am quite concerned.

  157. the end of an era by Anonymous Coward · · Score: 0

    Even UNIX-types are finally embracing C++. Haha, this feels good.

  158. Re:GCC should remain small and fast by Anonymous Coward · · Score: 0

    You mean at compile time, right?

  159. Re: progress by blippo · · Score: 1

    I don't know if it's intelligence that's needed to code C++.

    The required credentials rather seems to be a great patience.

  160. Re:too bad GCC is not relevant anymore thanks to L by interval1066 · · Score: 1

    There are a few 16 bit platforms that obviously can't use GCC, so maybe most, but not all. Sometimes 32 bits are simply to wide for some embedded projects.

    --
    Python: 'And then suddenly you have a language which says "we're all stuck with whatever the whiniest coder wants".'