Subject: Re: [boost] [#pragma once]
From: Lars Viklund (zao_at_[hidden])
Date: 2012-11-17 14:21:27
On Sat, Nov 17, 2012 at 04:12:34AM +0800, Yanchenko Maxim wrote:
> 10.04.2009, 23:26, "Marcus Lindblom" <macke_at_[hidden]>:
> >> Â In addition #pragma once may be faster than #ifndef/#endif because the
> >> Â compiler is not even going to open the file a second time to parse the
> >> Â #ifndef/#endif.
> > I've seen benchmarks that say some compilers (gcc, msvc) are smart
> > enough to recognize #ifndef/#endif and do the #pragma once equivalent.
> > (i.e. there's no discernable performance difference.)
> > Can't find the link now though.. :(
> It's in the docs of GCC, for example (even the ancient version 2.95.0 was optimized not to read same file twice if guards surround the whole file):
Beware that #pragma once is not supported on some of the toolchains that
Boost pretends to target (SunStudio, etc.), and more importantly, has
wildly diverging behaviour when it comes to symlinks and hardlinks, not
to matter over network filesystems or multiple mounts of the same
It also runs into issues with duplicated headers, or replacement
Blindly trusting #pragma once in a cross-platform setting is very scary.
Personally I only use it if I know very well the settings I'm deploying
code myself in.
-- Lars Viklund | zao_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk