C++ Logo

SG10

Advanced search

Subject: Re: [SG10] Feature test macros: always available, or in a header?
From: Richard Smith (richard_at_[hidden])
Date: 2013-05-10 19:25:33


On Tue, May 7, 2013 at 1:00 PM, John Spicer <jhs_at_[hidden]> wrote:

> I'm not personally fond of that direction.
>
> At least for EDG, and I suspect others, the set of feature supported is
> going to depend on command-line options, which would mean that we'd have to
> define one set of macros (or something) to allow the <features> header to
> define another set. It also makes it more likely that you could have a
> <features> file that doesn't actually match what the compiler does.
>

Since our names are reserved identifier, an implementation can predefine
them and provide a <features> which does nothing.

This allows feature test macros to be provided (a) with no compiler
changes, (b) retroactively for an implementation which was released prior
to our recommendations (provide a <features> which checks the compiler and
version, and use -D__cpp_lib_header_features), and (c) with (essentially)
zero cost for programs which do not use the macros. This also happens to be
standardizing existing practice ;-)

That said, I agree with Clark that quantifying the cost in (c) would be
useful. I have informally heard that this cost is measurable (especially
for things like configure scripts which build a large number of tiny
programs), but I've never seen numbers.

> John.
>
> On May 7, 2013, at 3:17 PM, Richard Smith <richard_at_[hidden]> wrote:
>
> > Hi,
> >
> > Has any thought been given to putting the feature-test macros into an
> implementation-supplied header, instead of predefining them? This would
> allow us to remove the cost associated with predefining these macros, for
> translation units which don't need them. Instead, we could supply a single
> predefined macro indicating whether the header is available, and user code
> would write something like:
> >
> > #ifdef __cpp_lib_header_features
> > #include <features>
> > #endif
> >
> > #ifdef __cpp_relaxed_constexpr
> > constexpr
> > #endif
> > size_t strlen(const char *p) { /* ... */ }
> >
> > ... and so on.
> > _______________________________________________
> > Features mailing list
> > Features_at_[hidden]
> > http://www.open-std.org/mailman/listinfo/features
>
>



SG10 list run by herb.sutter at gmail.com