User: Password:
Subscribe / Log in / New account

The Gnu Compiler Collection, Version 3.4

The Gnu Compiler Collection, Version 3.4

Posted May 6, 2004 7:18 UTC (Thu) by joib (subscriber, #8541)
Parent article: The Gnu Compiler Collection, Version 3.4

Only one precompiled header can be used in a particular compilation. This condition implies that a source file which includes multiple header files will only benefit from the precompiled support for exactly one of those headers. The workaround for this is to create a monolithic header file which includes all other header files, and use only this header file from within the source.

This sort of breaks the simple rule that "include files should never include include files", found IMHO for good reasons in many style guides.

(Log in to post comments)

The Gnu Compiler Collection, Version 3.4

Posted May 7, 2004 18:43 UTC (Fri) by nobrowser (guest, #21196) [Link]

What are the good reasons?

In my own style, every header file is self-contained, #include-ing any other
headers that declare types and macros it mentions. This way people who edit
the top source file are free from worrying about the order of #include-s.

I dislike the idea of a single monolithic header file too, though, for a
different reason: it introduces unneeded dependencies. If you include the
monolithic header in all C files, and then modify _any_ header whatsoever,
everything will be recompiled.

Acutally, that's only true if you generate the dependencies automatically.
If you can keep the details of which source depends on which header and
maintain Makefiles manually you're fine. Still a headache, though.

The Gnu Compiler Collection, Version 3.4

Posted May 9, 2004 22:40 UTC (Sun) by alextingle (guest, #20593) [Link]

When lots of header files refer to one another, large project builds tend to become unmanagable. One change to a single header file can force the recompilation of hundreds of objects. This can slow development to a crawl.

The preferred alternative is to use forward declarations where possible in the header file itself, and put the #include in the body file.

Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds