Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Does Visual Studio not optimize #include guards as-is? Other (better?) compiler do so, and I imagine it is quite easy. Commented Mar 4, 2010 at 6:11
  • 3
    Why do you put the pragma after the ifndef? Is there a benefit? Commented May 13, 2014 at 23:04
  • 3
    @user1095108 Some compilers will use the header guards as delimiter to know if the file contain only code that have to be instantiated once. If some code is outside the header guards, then the whole file might be considered maybe instantiable more than once. If that same compiler don't support pragma once, then it will ignore that instruction. Therefore, putting the pragma once inside the header guards is the most generic way to make sure that at least header guards can be "optimized". Commented May 14, 2014 at 10:52