GCC in C++

I’m very pleased to see that the GCC steering committee has agreed to permit GCC to be written in C++. At one time RMS, who is a member of the steering committee, had felt that C++ was never appropriate for systems programs like GCC. It’s good to see that he has apparently come around.

There has been a long effort to prepare for this, by moving GCC’s code base from C to the common subset of C and C++. While people naturally think of C++ as an extension to C, they are different languages and there is a lot of C code which is not valid C++. In the GCC code base, one of the biggest issues was that enums are more restricted by the type system in C++ than they are in C. Another was that in C++ you may not use the same name as a typedef and a struct tag, except for the special case of making the struct tag be a typedef for the struct itself.

Gabriel Dos Reis did the first substantial work on moving the GCC code base to the common subset, and many other people contributed. I think it’s fair to say that I did the lion’s share of the work, starting with my surprise presentation on the advantages of C++ at the 2008 GCC Summit. I did a lot of work to improve the -Wc++-compat warning option to warn about C code which was not in the C/C++ common subset, and I did a lot of work to make GCC code compile with that option without warnings.

C++ will not magically make the GCC code base better. However, I believe that it will give us some useful tools to incrementally improve the code base over time, making it easier to read, easier to modify, and more efficient. I say this not based on theory, but on my experiences with gold and with the gccgo frontend. I’ve already started writing some draft C++ coding conventions which I hope we can use to guide our efforts.


Posted

in

by

Tags:

Comments

4 responses to “GCC in C++”

  1. fche Avatar

    Thanks, Ian, for your work on this.

  2. reid.kleckner Avatar
    reid.kleckner

    Do you have any particular sections of GCC in mind for migration to C++?

  3. Ian Lance Taylor Avatar

    I think everybody’s favorite example would be to rewrite vec.h using std::vector. Another logical candidate would be the pass manager.

    Longer term, I hope to use smart pointers to implement a type safe adjustment of fold-const.c so that it can allocate trial trees in a pool and only copy them to GC memory if they are used. Right now I suspect that fold-const generates a lot of garbage which the collector has to pick up.

  4. redbrain Avatar

    I’m becoming tempted to use C++ now in my front-end simply to get away from those warnings on mixed declarations on C89 and no C++ style comments, it may be a good idea for me to move sooner than later esp if the GCC code base wants to migrate.

Leave a Reply