|
Boost : |
Subject: Re: [boost] [#pragma once]
From: Sid Sacek (ssacek_at_[hidden])
Date: 2009-04-10 18:34:23
>> #if defined( _MSC_VER ) && ( _MSC_VER >= 1020 )
>> # pragma once
>> #endif
> IMO, there is absolutely no reason to /rely/ on non-standard
> features even if /all/ compilers supported it in this case.
> Steven Watanabe
Just to make a small point; this is from the C++ standard...
[quote]
16.6 Pragma directive [cpp.pragma]
1 A preprocessing directive of the form
# pragma pp-tokensopt new-line
causes the implementation to behave in an implementation-defined
manner. The
behavior might cause translation to fail or cause the translator or
the resulting
program to behave in a non-conforming manner. Any pragma that is
not recognized
by the implementation is ignored.
[unquote]
If unrecognized pragmas are ignored, then I don't see why boost
developers should jump
through a hoop to satisfy the "el-cheapo" compilers. In other words, if
a compiler gives
a warning about the #pragma-once, then let the programmer turn off the
warning locally
for the build, which is usually done in a single location within a
makefile.
On the other hand, every boost.hpp file has to surround the "#pragma
once" with the
silly looking guards.
I tried this experiment just to see what happens. I added the
non-existing #pragma to
my code and got the following warning:
#pragma once_upon_a_time
foo.cpp(20) : warning C4068: unknown pragma
My opinion is that the boost headers can happily contain the following
code:
#ifndef __HEADER_FILE_GUARD__
#define __HEADER_FILE_GUARD__
#pragma once
...
#endif
I have not yet heard about a compiler that doesn't support this #pragma.
I would be
surprised if a single developer calls up to complain about this. The
compilers that
warn against this #pragma can turn off the warnings with a single
makefile change,
like I mentioned before.
Regards,
-Sid Sacek
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk