Slashdot Mirror


GCC Gets PCH Support And New Parser

Screaming Lunatic writes "GCC will finally get precompiled header support which should help with faster compile times. GCC will also be fitted with a new recursive descent parser that fixes more than 100 bugs in GCC. I'm not sure how they decomposed C++ into a context free grammar so that it could be parsed using recursive descent."

5 of 83 comments (clear)

  1. Re:Why the extra step? by PD · · Score: 5, Insightful

    No, object files are built one at a time with a makefile. The correlation would be if we just typed "gcc" in a directory and the compiler built every cpp file into an object. What if I didn't want a file compiled? What if that file was supposed to be copied into a directory after it was built with another tool? In that case, gcc would be doing the wrong thing by building every .o automatically.

    A makefile lets me control the building of each and every .o file myself, allowing for all sorts of things that I might want to do.

    Precompiled headers should work the same way, or they won't be as flexible as the .h files.

  2. Well done GCC, but.... by peterpi · · Score: 4, Insightful

    ... in my experience, good use of forward declarations (to avoid unrequired chains of #include), combined with simply putting less in each .c file is a lot more effective than adding the complication of precompiled headers into your build process.

    1. Re:Well done GCC, but.... by sohp · · Score: 4, Insightful

      That's exactly the sort of rule of thumb that John S. Lakos talks about in his terrific book, Large-Scale C++ Software Design (ISBN: 0201633620). Basically, pre-compiled headers are for developers who are too lazy or inexperienced to manage inter-module dependencies efficiently.

  3. Re:ANTLR? by bhurt · · Score: 3, Insightful

    The problem is that C++ requires basically an infinite k to parse context free. For example, consider what the compiler does when it sees a set of tokens like:
    a d;

    Now, is this:
    a) a strange but legal expression parsed
    like:
    (a ) d;

    Both are legal interpretations. The only way you can tell is by looking at the type of a before parsing the rest of the expression. And even this may not help. IIRC, the issue may be undecidable, as template names are in a different "namespace" than variable names (i.e. I can have both a template type and a variable with the same name at the same time.

    Note that d being a more complex expression than just a name also allows you to decide. But we're up to a k=7 on the simple case. Make b and c arbitrarily complex expressions themselves, and you can make k need to be arbitrarily large. Or heck, consider:
    a d, e, f;
    (three new variables d, e, and f, or four different expressions combined with the comma operator?).

    And it doesn't matter how infrequent this code construct is. The compiler has to deal with this situation, and situations like it. And deal correctly. C++ simply is not LALR(1) parsable, and likely not really parsable at all. It's a fundamental flaw in the language.

    And this does cost. YACC was developed because it's easier to write and maintain parsers in YACC than hand-rolled parsers for any nontrivial but LALR(1) parsable language. Time and effort will go to the development and maintainance of the compilers. For commercial products, this means higher prices. For free products like GCC, this means fewer new features and fewer bugfixes in other parts of the code.

    Brian

  4. Re:PCH is so 1993... by Anonymous Coward · · Score: 1, Insightful

    There was an ample supply of eyeballs on the GCC project but eyeballs can't type. The extra time was needed to track down brains and hands to change the code.