Opened 15 years ago

Closed 13 years ago

#1532 closed Feature Requests (wontfix)

#pragma once

Reported by: NN Owned by: John Maddock
Milestone: Boost 1.36.0 Component: config
Version: Boost 1.34.1 Severity: Optimization
Keywords: Cc:

Description

The most of modern compilers do support #pragma once feature. This can reduce significantly the compilation time. Boost should use this too.

Proposal: In boost/config.hpp define the BOOST_ONCE macro: (Of course this should be defined in the right compiler configuration header file)

!#cpp
// VC >4.0
// GCC >=4.30
// ICC >10
#if (defined(_MSC_VER) && _MSC_VER > 1000) || \
    (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 30) || (__GNUC__ > 4))) || \
    (defined(__ICC) && __ICC > 1000)
#   define BOOST_ONCE once    
#else
#   define BOOST_ONCE message("")
#endif

Using in other files: boost/xxx/yyy.hpp

!#cpp
#ifndef BOOST_XXX_YYY_INCLUDED
#define BOOST_XXX_YYY_INCLUDED

#include <boost/config.hpp>

#pragma BOOST_ONCE

#endif // BOOST_XXX_YYY_INCLUDED

Change History (5)

comment:1 by niels_dekker, 15 years ago

Thanks for your ticket. But the use of #pragma once appears rather controversial. You may want to check out the discussion on comp.std.c++, in December 2007: #pragma once in ISO standard yet? (73 postings!)

GCC 4 has already declared #pragma once as being obsolete: Obsolete once-only headers

comment:2 by NN, 15 years ago

Defining the macro is a good solution for this program, because if #pragma once will be declared as unsupported in GCC 5.x it may do nothing.

Anyway #pragma once does decrease the compilation time, so there is no reason not to define the macro and use it. Because it can be simply disabled in a simple and a standard way.

Thanx.

in reply to:  description comment:3 by Shunsuke Sogame <pstade.mb@…>, 15 years ago

Replying to NN:

The most of modern compilers do support #pragma once feature. This can reduce significantly the compilation time.

Seems cool macro. Which compiler would compile faster?

Regards,

comment:4 by viboes, 13 years ago

Component: Noneconfig
Owner: set to John Maddock

comment:5 by John Maddock, 13 years ago

Resolution: wontfix
Status: newclosed

I thought we did some tests and decided it wasn't worth the effort? Compilers are mostly smart enough now not to need this hint.

In any case the proposed solution won't work: #pragma message isn't supported by anything except MSVC I believe, so every other compiler would emit a warning about an unknown pragma :-(

We could define a BOOST_HAS_PRAGMA_ONCE, but this would basically be synonymous with _MSC_VER I believe and therefore superfluous, especially now the only other case - GCC - has deprecated this.

Closing down for now, please reopen if a better solution presents itself and/or if you have convincing use cases (with data!) :-)

John.

Note: See TracTickets for help on using tickets.