Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
GNU is Not Unix Programming

GCC Moving To Use C++ Instead of C 546

An anonymous reader writes "CodeSourcery's Mark Mitchell wrote to the GCC mailing list yesterday reporting that 'the GCC Steering Committee and the FSF have approved the use of C++ in GCC itself. Of course, there's no reason for us to use C++ features just because we can. The goal is a better compiler for users, not a C++ code base for its own sake.' Still undecided is what subset of C++ to use, as many contributors are experts in C, but novices in C++; there is a call for a volunteer to develop the C++ coding standards."
This discussion has been archived. No new comments can be posted.

GCC Moving To Use C++ Instead of C

Comments Filter:
  • Re:What... (Score:4, Informative)

    by Ckwop ( 707653 ) on Tuesday June 01, 2010 @05:19AM (#32416048) Homepage

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

    Enjoy [google.co.uk]

  • Incorrect headline (Score:5, Informative)

    by Letharion ( 1052990 ) on Tuesday June 01, 2010 @05:27AM (#32416098)
    The headline says "Use C++ instead of C" which is incorrect. C++ is, as made obvious from the text, an option, not a requirement.
  • Re:What... (Score:2, Informative)

    by Anonymous Coward on Tuesday June 01, 2010 @05:34AM (#32416132)

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

  • by chocapix ( 1595613 ) on Tuesday June 01, 2010 @05:51AM (#32416224)

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

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

  • by Cyberax ( 705495 ) on Tuesday June 01, 2010 @06:28AM (#32416372)

    Because ObjectiveC is a slow shit?

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

  • by Anonymous Coward on Tuesday June 01, 2010 @06:57AM (#32416490)

    GCC already uses a garbage collector [gnu.org] internally although it has to be triggered explicitly.

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

  • Re:Finally! (Score:1, Informative)

    by Anonymous Coward on Tuesday June 01, 2010 @07:00AM (#32416512)

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

  • Re:C++? (Score:1, Informative)

    by Anonymous Coward on Tuesday June 01, 2010 @07:46AM (#32416738)

    Even Objective-C is better.

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

  • Re:thus a disaster (Score:5, Informative)

    by MadKeithV ( 102058 ) on Tuesday June 01, 2010 @07:46AM (#32416740)

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

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

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

  • Re:Seems odd... (Score:5, Informative)

    by mog007 ( 677810 ) <<moc.liamg> <ta> <700goM>> on Tuesday June 01, 2010 @07:51AM (#32416784)

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

  • Re:Seems odd... (Score:5, Informative)

    by Per Wigren ( 5315 ) on Tuesday June 01, 2010 @08:01AM (#32416850) Homepage
    It was Flow-Matic aka B-0 [wikipedia.org] which later kind of evolved into COBOL, also designed by her.
  • by Anonymous Coward on Tuesday June 01, 2010 @08:10AM (#32416890)

    If anyone is interested about the speed of various different dispatch mechanisms, I've done some profiling [oriontransfer.co.nz]

  • by ommerson ( 1485487 ) on Tuesday June 01, 2010 @08:34AM (#32417054)
    Quite simply because STL is the embodiment of several decades of algorithms and data structures research work. In many cases, use of STL results in near optimal code. In raw C, you're left to yourself to write your own collections and algorithms. You have to try pretty hard to surpass the performance of STL. Do you want compiler developers to constantly reinventing wheels or actually improving the compiler?
  • Re:Seems odd... (Score:2, Informative)

    by ommerson ( 1485487 ) on Tuesday June 01, 2010 @08:36AM (#32417074)
    C++ compilers have been implemented this way in the past, but it's a far from optimal approach for for modern C++ - hence why nobody does it any more.
  • by larry bagina ( 561269 ) on Tuesday June 01, 2010 @10:09AM (#32417954) Journal
    LLVM is a virtual machine, optimizer, and compiler infrastructure, not a compiler itself. Clang is written in c++ and support C, Objective C, and C++ (c++ support isn't complete but it self compiles and can compile boost and their own stl). gcc-llvm is a fork of gcc that uses llvm for the code generation. There's also dragonegg, which is a plugin for newer versions of gcc to use llvm code generation without any gcc modifications (well, I think there's a small patch involved). Side note, it's curious how they finally allowed plugins.
  • Re:Seems odd... (Score:3, Informative)

    by siride ( 974284 ) on Tuesday June 01, 2010 @10:34AM (#32418248)
    What you said is true of any language. More apropos of the subject, it's not that simple: http://languagelog.ldc.upenn.edu/nll/?p=2290 [upenn.edu]
  • Using STL frees you from having to do manual memory management

    Here, let me fix that for you:

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

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

  • Re:C++? (Score:3, Informative)

    by siride ( 974284 ) on Tuesday June 01, 2010 @11:08AM (#32418654)
    There is no such thing as actual pass-by-reference. Sure, a language might have fancy syntax for it, but it gets boiled down to pointer-to-a-value-which-is-itself-a-value. C just skips the sugar.
  • Re:What... (Score:5, Informative)

    by MikeBabcock ( 65886 ) <mtb-slashdot@mikebabcock.ca> on Tuesday June 01, 2010 @11:13AM (#32418750) Homepage Journal

    Or even from the GCC build instructions [gnu.org]:

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

    The bootstrapping process will complete the following steps:

         

    • Build tools necessary to build the compiler.
           
    • Perform a 3-stage bootstrap of the compiler. This includes building three times the target tools for use by the compiler such as binutils (bfd, binutils, gas, gprof, ld, and opcodes) if they have been individually linked or moved into the top level GCC source tree before configuring.
           
    • Perform a comparison test of the stage2 and stage3 compilers.
           
    • Build runtime libraries using the stage3 compiler from the previous step.
           
  • Re:Choices, choices (Score:3, Informative)

    by binarylarry ( 1338699 ) on Tuesday June 01, 2010 @11:24AM (#32418910)

    Actually you have it almost completely backwards.

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

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

  • by Per Abrahamsen ( 1397 ) on Tuesday June 01, 2010 @11:36AM (#32419050) Homepage

    The Ada front end is written in Ada.
     

  • Re:Choices, choices (Score:3, Informative)

    by binarylarry ( 1338699 ) on Tuesday June 01, 2010 @04:22PM (#32423256)

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

"Protozoa are small, and bacteria are small, but viruses are smaller than the both put together."

Working...