This is the mail archive of the
mailing list for the GCC project.
Re: #pragma once
- From: Ian Lance Taylor <iant at google dot com>
- To: Drgt <dragity at mail dot ru>
- Cc: gcc at gcc dot gnu dot org
- Date: 14 Aug 2006 12:41:16 -0700
- Subject: Re: #pragma once
- References: <op.td8ebep9qs9lg4@organ>
Drgt <email@example.com> writes:
> It seems, that "#pragma once" isn't in ISO, and will never be, especially
> because it is Microsoft (am I right ?) C extension.
I believe that gcc was actually the first compiler to implement
"#pragma once". It was added back in 1989 in gcc 1.35 by RMS. It is,
perhaps, ironic that it is now considered to be a Microsoft extension.
Then in 1991 RMS added support for automatically detecting when a
header file puts all the non-comment text inside #ifndef/#define/
#endif. When that happens, and gcc sees another #include for the same
header file, and the relevant macro is #defined, gcc will skip reading
the header file entirely. That first appeared in gcc 2.0. Given that
ability, RMS decided that there was no need to support #pragma once,
and, since he doesn't like #pragma (or at least didn't at the time),
he changed #pragma once at that time to issue an unavoidable warning.
Note that #pragma once still worked; it just issued a warning.
But #pragma once was still used in practice, so the warning was
removed by Jason Merrill in 2003, for gcc 3.3.
In short, #pragma once works fine today. What makes you think that it