The nonstandard #pragma once
feature is implemented on practically all C++ compilers, but the C++ standard excludes it.
The usual explanation of why #pragma once
, or some language construct that does what #pragma once
does, has been excluded from the C++ standard is that hard links and copied header files either break #pragma once
or provoke the compiler to heuristics. Fair enough, heuristics are normally incompatible with the C++ philosophy anyway, but regarding plain breakage: there are many useful language features you can break, not only #pragma once
. The normal C++ way to manage such breakage is to let the compiler issue an optional warning in doubtful instances. After all, C++ is purposely designed to let one program unsafely and/or unportably when one wishes to do so. Besides, the unsafety and/or unportability of #pragma once
is pretty minimal. It just isn't that easy to abuse.
Why is #pragma once
excluded from the standard when other abusable but useful language features are typically included? Is there something special about #pragma once
?
Also, where can one read the recent deliberations of the standards committee in the matter? Has some committee member, or committee follower, published a recent summary of the debate?
There are a few simple reasons:
#pragma once
, i.e., it isn't considered a problem.#pragma once
have a sufficient majority for it to be stopped quite quickly.There was a recent discussion on the proposals mailing list (see isocpp.org for how to sign up; I can't get to this site at the moment, though). I didn't follow it too thoroughly, though. Quickly browsing over it I saw the four reasons given above (the forth I added after browsing).
Here are some references from the recent mailing list discussion: