
Incredibuild (xoreax) and other parallel compilation systems have
[ Graham wrote: ] problems with pragma once I'm not sure what the "problems with pragma once" are by Graham's statement above. So far, I have heard that #pragma once doesn't work right on some platforms. That tells me the programmer cannot rely on it, but that doesn't indicate that it cannot be used in the program. What is clear is that #pragma once works on some platforms. Also, for the platforms that it doesn't work on, the use of #ifndef is absolutely required. Boost is a cross-platform library, so that means cross-platform programs needs to look something like this: #ifndef HEADER_FILE_GUARD #define HEADER_FILE_GUARD #pragma once If the above code gives a pragma warning, the warning can be turned off or simply be ignored. I have not yet heard any objections for the above code. If that's still not good enough for every compiler that's out there, the variation below - which was already proposed to boost - should be good enough. Each platform can decide what to do with their version of the BOOST_ONCE macro. #ifndef HEADER_FILE_GUARD #define HEADER_FILE_GUARD #pragma BOOST_ONCE I'm starting to feel like the people in charge of the boost libraries aren't even listening in on this conversation. I would like to hear some opinions and some votes about the above code, especially opinions from the boost heavy-weights. I need to know I'm not just wasting everybody's time here. If something like the above code was acceptable to the boost custodians, I would be happy to make the appropriate changes myself. I realize that this topic has already been discussed for the C++ language in general and, for the most part, has been ignored. However, I'm going to add a twist to the pragma-once statement that was never brought up in discussion. What should solve all of the issues concerning the header guards is the following variation to #pragma once: #pragma once( HEADER_FILE_GUARD ) The above line of code includes both the pragma-once statement, but is also protected by the unique HEADER_FILE_GUARD token. Its meaning is clear and concise. This implies that the #ifndef, #define, and #endif are no longer required, and satisfies everybody's compiling needs. It would be great if the current preprocessor could be used to implement that, but I don't think it can. The current existing alternative within the boost code is just plain hideous. Just to remind you all, here it is one more time: #ifndef __BOOST_HEADER_GUARD__ #define __BOOST_HEADER_GUARD__ #if defined( _MSC_VER ) && ( _MSC_VER >= 1020 ) # pragma once #endif Sincerely, -Sid Sacek