[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: The g++ preprocessor: Include Guards
From: |
Bernd Strieder |
Subject: |
Re: The g++ preprocessor: Include Guards |
Date: |
Wed, 20 Jun 2007 13:28:46 +0200 |
User-agent: |
KNode/0.10.4 |
Hello,
gutmant@gmail.com wrote:
> Say you have a file, a.h with an include guard.
> If you include it twice and look at the preprocessed output, you see
> there's no sign for the second inclusion.
> However, if you include it twice - once from a relative path, and once
> from an absolute one - you see that the second inclusion indeed occurs
> (enters the file and leaves immediately due to the include guard).
>
> Why does this happen(I have my speculations, but I want some
> reassurance...), and is there any way to make it always act like in
> the latter case?
AFAIK gcc has some features recognizing include guards, avoiding opening
a guarede file a second time, and thus saving even more than the
include guard itself. Since opening a file can be costly due to OS
calls, this has been found an important optimization.
That include guard optimization probably is based on a simple heuristic,
which you have broken by using relative and absolute filenames.
Start reading with http://en.wikipedia.org/wiki/Pragma_once
and follow the links to gcc
Or see the section "Once-Only Headers" in the docs of cpp, the C
preprocessor.
I think you can easily break the employed heuristics to reach your goal.
Bernd Strieder
- The g++ preprocessor: Include Guards, gutmant, 2007/06/20
- Re: The g++ preprocessor: Include Guards,
Bernd Strieder <=
- Re: The g++ preprocessor: Include Guards, gutmant, 2007/06/20
- Re: The g++ preprocessor: Include Guards, Bernd Strieder, 2007/06/20
- Re: The g++ preprocessor: Include Guards, gutmant, 2007/06/20
- Re: The g++ preprocessor: Include Guards, Bernd Strieder, 2007/06/20
- Re: The g++ preprocessor: Include Guards, gutmant, 2007/06/20
- Re: The g++ preprocessor: Include Guards, Bernd Strieder, 2007/06/21
- Re: The g++ preprocessor: Include Guards, gutmant, 2007/06/21
- Re: The g++ preprocessor: Include Guards, Bernd Strieder, 2007/06/21
- Re: The g++ preprocessor: Include Guards, gutmant, 2007/06/21