Results 1 to 10 of 11

Thread: GCC Compiler Migrating To Be More C++ Based

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    13,417

    Default GCC Compiler Migrating To Be More C++ Based

    Phoronix: GCC Compiler Migrating To Be More C++ Based

    Last week at Google's offices in London there was a gathering of GCC (GNU Compiler Collection) developers to discuss various topics from C++0x and GDB to the compiler's plug-in API. There are notes from this 2011 GCC Gathering on the GCC Wiki for those interested, but perhaps most interesting was their discussion surrounding the planned migration to C++. GCC itself is largely written in C at this point, but there's an effort under-way to switch more of this compiler code to being more C++ based...

    http://www.phoronix.com/vr.php?view=OTU5Nw

  2. #2
    Join Date
    Oct 2007
    Posts
    912

    Default

    Just a subtle correction after reading the document, is that it's likely the churn will come about from differences of opinion of devs, not from c++ inclusion itself.

  3. #3
    Join Date
    Sep 2008
    Posts
    989

    Default

    As long as it doesn't affect the quality of the generated code, I don't care. Slow down and bloat the compiler; as far as my use cases go, it doesn't affect me. My CPU can chew through your templates and virtual function tables. Hopefully they buy you some degree of programmer-friendliness for gcc hackers.

    Compile time is not really an important stat for most people compiling stuff. Correctness and compatibility -- so that your code "just works" as intended -- and performance of the generated binaries is what matters the most.

  4. #4
    Join Date
    May 2009
    Location
    Richland, WA
    Posts
    132

    Default

    C++ is best described as making an octopus out of a dog by nailing extra legs to it.

    Bad move IMHO.

  5. #5

    Default

    Quote Originally Posted by Obscene_CNN View Post
    C++ is best described as making an octopus out of a dog by nailing extra legs to it.

    Bad move IMHO.
    That's still better than C, which is like a dog with no legs at all.

  6. #6
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,762

    Default

    Quote Originally Posted by allquixotic View Post
    As long as it doesn't affect the quality of the generated code, I don't care. Slow down and bloat the compiler; as far as my use cases go, it doesn't affect me. My CPU can chew through your templates and virtual function tables.
    Your CPU doesn't need to chew through that. Those things aren't computationally intensive. There's nothing to chew through.

  7. #7
    Join Date
    Nov 2007
    Posts
    1,024

    Default

    Anyone who thinks C++ makes code slower than writing the exact same code with the exact same behavior in more obtuse C code is an idiot, doesn't understand compilers, languages, CPUs/assembler, basic runtime architecture, operating systems, or pretty much anything about programming other than what they can read from other clueless, uninformed dipshits on the Interwebz. A template is no more bloated than a pile of macros that do the same thing. A virtual function call is no slower than using a function pointer table. An overloaded addition operator is no slower than calling an add_foo function. Etc. You could argue that exceptions cause overhead... if we were still in the 1990's and modern ABIs didn't have zero-overhead exception implementations, which GCC uses by default.

    Just sayin'.

  8. #8
    Join Date
    Oct 2008
    Posts
    2,908

    Default

    Quote Originally Posted by RealNC View Post
    Your CPU doesn't need to chew through that. Those things aren't computationally intensive. There's nothing to chew through.
    I think virtual functions add an extra layer of pointer indirection - and I'm sure you can design poorly written C++ that slows things down.

    However, in general, there's absolutely no reason a C++ app should be any slower than one written in C. There are even a few optimizations that apply only to C++ and aren't possible in C.

  9. #9
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,762

    Default

    Quote Originally Posted by smitty3268 View Post
    I think virtual functions add an extra layer of pointer indirection
    The impact is so small that using the term "chewing through it" is like saying that you need a chainsaw to cut a toothpick in half

    and I'm sure you can design poorly written C++ that slows things down.
    That's true for any language, of course.

    However, in general, there's absolutely no reason a C++ app should be any slower than one written in C. There are even a few optimizations that apply only to C++ and aren't possible in C.
    Yep. And the vtable can sometimes be bypassed entirely by the compiler, even when using pointers. But in general, even if not, the impact is a non-issue. When C++ first appeared, people were running systems with 66MHz i486 CPUs, and it wasn't an issue even then. So trying to make this an issue on systems that are orders of magnitude faster than this is simply dumb C++ has been used so much for GUIs and such, that people tend to forget that C++ is actually a high performance, systems programming language.

  10. #10
    Join Date
    Nov 2007
    Posts
    1,024

    Default

    Quote Originally Posted by smitty3268 View Post
    I think virtual functions add an extra layer of pointer indirection
    Of course they do. Also obviously, if you actually _need_ virtual functions to implement a design, it turns out not having them is of significantly worse performance.

    Look at the OOP patterns in Linux articles on LWN. The nice big fast Linux kernel is basically filled with vtables, except they're all written by hand in C. There's just as much indirection going on there as there is in any C++ vtable. Except the C compiler doesn't know when or how to automatically de-vritualize functions...

    And sure, sometimes you don't need the extra level of indirection, and just storing a function pointer in the object instance is sufficient. Thankfully, unlike C#, Java, and almost every other "better than C++" OOP language out there, C++ is able to do all the things C can do just as fast as C can do them, so you can still just stick a function pointer in your objects in C++. And then wrap it in an inlined one-liner method so the call syntax stays just as clear (and just as IntelliSense-friendly).

    Idiot C++ programmers will -- like any other idiot programmer -- misuse a language, often because they don't understand the language, don't understand programming in general (most computer science majors fall into that category, sadly), or just don't understand the program they're trying to write. A competent C++ programmer knows how to design and architect a large framework, knows when to use and not to use polymorphism, virtual functions, abstraction, etc. and when to do things bare to the metal (or even when to offload the work into an external tool/language).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •