
On Mon, Jun 27, 2011 at 04:42:43PM -0400, Edward Diener wrote:
On 6/27/2011 12:59 PM, Stephan T. Lavavej wrote:
[Mateusz Loskot]
Is location of #pragma relevant? Meaning, having #pragma nested in #ifndef include guard vs. placing it in outer scope, makes difference or not?
VC doesn't care where the #pragma once is, but as I recall, other compilers care where the #ifndef is - they prefer it to be on the outside of everything else, except comments.
I doubt if any compiler cares where the #ifndef ( or #if !defined ) is.
I would reckon that compilers and preprocessor implementations may have fast-paths that they go into if they detect something that looks like an include guard very early in the file, where they can cheaply reject it if already included with a minimum of work, if they guarantee correctness. After, all, it's a very common operation, it's most probably very beneficial for cutting preprocessing costs.
It is just C++ after all and the preprocessor should handle it according to the C++ standard.
As long as you have the proper semantics, optimizing such a case would be quite allowed. -- Lars Viklund | zao@acc.umu.se