This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Avoiding Double Header Includes
- From: Ian Lance Taylor <iant at google dot com>
- To: Tom Browder <tom dot browder at gmail dot com>
- Cc: GCC-help <gcc-help at gcc dot gnu dot org>
- Date: Tue, 07 Sep 2010 18:02:42 -0700
- Subject: Re: Avoiding Double Header Includes
- References: <AANLkTi=WLT7yZRQC95yxPRxsCR0LhdwMXjvGN0G2Mw9r@mail.gmail.com>
Tom Browder <tom.browder@gmail.com> writes:
> The cpp manual states:
>
> <quote>
> CPP optimizes even further. It remembers when a header file has a
> wrapper `#ifndef'. If a subsequent `#include' specifies that header,
> and the macro in the `#ifndef' is still defined, it does not bother to
> rescan the file at all.
> </quote>
>
> Does that mean (1) the file is reopened but not scanned, or (2) does
> it mean the file is not even opened? It seems that (1) is probably
> the correct answer, but I'm looking for confirmation.
I believe that the file is not even opened.
> It makes a slight difference efficiency-wise, and there is a cpp
> "#pragma once" that will definitely avoid reopening the header after
> the first time it's read.
#pragma once is considered to be obsolete, because the default behaviour
is simpler.
Ian