
It seems to me the outer #ifdef works for MSVC as well. What's the extra benefit of embedding an inner #pragma once in this case? 在 2011-06-24五的 04:22 -0400,boost-request@lists.boost.org写道:
Message: 1 Date: Thu, 23 Jun 2011 21:43:02 +0000 From: "Stephan T. Lavavej" <stl@exchange.microsoft.com> To: "boost@lists.boost.org" <boost@lists.boost.org> Subject: Re: [boost] numeric_cast Message-ID:
Actually, the best thing to do is this:
#ifndef MYPROJECT_MYDIRECTORY_FOOBAR_HPP #define MYPROJECT_MYDIRECTORY_FOOBAR_HPP
#ifdef _MSC_VER #pragma once #endif // _MSC_VER
meow;
#endif // MYPROJECT_MYDIRECTORY_FOOBAR_HPP
This way, all compilers get the portable idempotency guard. Because it's on the outside, GCC (and possibly other compilers) will magically recognize it and avoid opening the header file twice. And the #pragma once for MSVC also instructs it to avoid opening the header file twice, which can improve build perf and can't hurt.
Stephan T. Lavavej Visual C++ Libraries Developer