Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2002-12-06 08:05:54

On Thu, 05 Dec 2002 15:43:27 -0500, David Abrahams
<dave_at_[hidden]> wrote:

>Hmm. Well, if it's non-conforming we probably shouldn't use it. If
>it's just a vc bug, we could do something like
> # ifdef BOOST_MSVC
> # define BOOST_WORKAROUND(symbol, test) BOOST_DEFINED_##symbol && symbol test
> ...
> # else
> # define BOOST_WORKAROUND(symbol, test) (defined(symbol) && symbol test)
> #else
> # define BOOST_WORKAROUND(symbol, test) 0
> #endif

The C++ standard isn't clear enough about it. It says (emphasys mine):

   Preprocessing directives of the forms

   # if constant-expression new-line groupopt
   # elif constant-expression new-line groupopt

   check whether the controlling constant expression evaluates to

   4 Prior to evaluation, macro invocations in the list of
   preprocessing tokens that will become the controlling constant
   expression are replaced (except for those macro names modified by
   the defined unary operator), just as in normal text. If the token
   defined >>is generated<< as a result of this replacement process
   or use of the defined unary operator does not match one of the two
   specified forms prior to macro replacement, the behavior is

The issue is what "is generated" means. Strictly speaking, your code
doesn't "generate" it; the token is already lexed in phase 3 and macro
expansion just replaces the macro name with a sequence of tokens that
contains 'defined'. A situation where it is really "generated" would
be e.g. when it is the result of ## operator. Well, as I said the
standard doesn't make it clear which case it refers to, however the C
(not C++) committee recently responded to a similar issue with this:

It seems to me that it doesn't leave much room for doubts for C (note
especially the suggested technical corrigendum). And since we don't
have more precise information for C++ I think such a construct is best
avoided. Just my opinion?


Boost list run by bdawes at, gregod at, cpdaniel at, john at