<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>#pragma once</title><link>http://blogs.msdn.com/ericflee/archive/2008/04/17/pragma-once.aspx</link><description>Most C++ compilers now support the non-standard #pragma once compiler directive. This directive instructs the compiler to #include the file only once in a single compiland, and replaces the old C-style header sentinels (often called #include guards ).</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: #pragma once</title><link>http://blogs.msdn.com/ericflee/archive/2008/04/17/pragma-once.aspx#8405161</link><pubDate>Fri, 18 Apr 2008 02:31:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8405161</guid><dc:creator>steven</dc:creator><description>&lt;P&gt;I generally use both. #pragma once really is a very useful thing. Pragmas are supposed to allow for implementation-specific behaviour. I don't really see a problem with its behaviour being copied in another implementation. Apparently, the creators of GCC agree because the feature was un-deprecated in GCC 3.4 (release in 2004).&lt;/P&gt;
&lt;P&gt;The Wikipedia entry on #pragma once (&lt;A href="http://en.wikipedia.org/wiki/Pragma_once" target=_new rel=nofollow&gt;http://en.wikipedia.org/wiki/Pragma_once&lt;/A&gt;) mentions this. And indeed a simple test shows there are no warnings when using it (gcc version 4.2.2 on my system).&lt;/P&gt;</description></item><item><title>re: #pragma once</title><link>http://blogs.msdn.com/ericflee/archive/2008/04/17/pragma-once.aspx#8409038</link><pubDate>Fri, 18 Apr 2008 23:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8409038</guid><dc:creator>int19h</dc:creator><description>&lt;P&gt;The reason why the GCC folks are backing out of it, and why the ISO committee will never approve it, is because it is nearly impossible to define the semantics of having "#pragma once" in a header in a proper fashion, even on a single platform. Specifically, the issue is with determining that the file being included now is one of those that have been included earlier.&lt;/P&gt;
&lt;P&gt;Do we just compare path names? What if a file is referenced using two different relative pathnames? Do we always resolve to absolute, and then compare? Alright, then what about symbolic links and hardlinks - do we bother to check for those, or not? Note that these do not have to be on the file itself, but also on any of the directories in the path, so we'd have to check for them all. And when hardlinks are involved, on some platforms (all Unix-likes?), there's no single "primary" file name - they're all the same. Then, of course, there are network shares and UNC pathes - if, say, I share my INCLUDE folder, and then reference the same header twice, once using full UNC path, the second time using a local filesystem path, does the compiler still have to detect that? What if I'm referencing a remote server which shares the same folder under two different names? etc...&lt;/P&gt;
&lt;P&gt;The only bulletproof way here is to compare the contents of files (or a sufficiently strong hash), but then you have to read the entire file anyway, so there isn't a huge speed benefit. On the other side, gcc at least can optimize the common header-guard pattern so that it's not any slower than #pragma once; any other compiler can do the same (and indeed, many do, though not, as I understand, MSVC).&lt;/P&gt;
&lt;P&gt;On a side note, by far the easiest way to ensure that header guards are unique and also stand out is to use GUIDs for them.&lt;/P&gt;</description></item></channel></rss>