Since other irreconcilable but useful features have been standardized, why not #pragma once?

The custom function is #pragma once

implemented for almost all C ++ compilers, but the C ++ standard excludes it.

The usual explanation for why, #pragma once

or some language construct that does what it does #pragma once

, has been dropped from the C ++ standard, is that hard links and copied header files break on #pragma once

or provoke the compiler to heuristic. Fair enough, heuristics are usually incompatible with C ++ philosophy anyway, but as far as simple breakage is concerned: there are many useful language features that you can break, not just #pragma once

. The usual C ++ way to handle this kind of breakage is to let the compiler issue an optional warning in doubtful cases. After all, C ++ is intentionally designed to make one program unsafe and / or hectic whenever you want. In addition, insecurity and / or failure#pragma once

pretty minimal. It's just not easy to abuse.

Why #pragma once

excluded from the standard when other irreconcilable but useful language features are usually included? Is there something special about #pragma once

?

Also, where can you read recent discussions of the standards committee on this issue? Has any committee member or committee follower posted a recent summary of the debate?

+3


source to share


2 answers


There are several simple reasons:

  • This is more complicated than it was usually supposed to be implemented and specified. The argument that it is implemented doesn't have a lot of water, since implementations usually don't consider approaches to distorting a function.
  • The time on the committee is much more wisely spent working on modules that make most of the preprocessor unnecessary than trying to improve on what we want to get rid of.
  • There is a simple detour around (including guards) for absences #pragma once

    , meaning this is not considered a problem.
  • It seems the existing implementations actually behave differently, which seems to be the root of one of the latest discussions. Of course, this means that standardization will be good, but then it will immediately start to contradict 2 and the discussions will be difficult because different parties will want to keep their respective behavior.
  • I haven't searched too thoroughly, but I haven't seen a proposal either: if no one writes a proposal [and walks it through the process], nothing will be standardized. However, I would fully expect the above reasons to discontinue the add proposal #pragma once

    have a sufficient majority to be stopped fairly quickly.

There was a recent discussion on the suggestions mailing list (see isocpp.org for registering, I can't get to this site at the moment though). However, I did not follow it too closely. Quickly looking through this, I saw four reasons above (the fourth one I added after browsing).



Here are some links from a recent mailing list:

+3


source


From my point of view, #pragma once

is a concrete instance of a standard directive #pragma

as described in section Β§16.6 of the standard ( draft ):

16.6. Pragma directive [cpp.pragma]

Form preprocessing directive

# pragma pp-tokens opt new-line makes the implementation behave in the implementation - in a certain way. The behavior can cause the translation to fail or cause the translator or the resulting program to behave in an inappropriate way. Any pragma that is not recognized by the implementation is ignored.



Standardization pragma once

will be quite challenging. Give also a look here: fooobar.com/questions/52094 / ...

+2


source







All Articles