|
Boost : |
From: Steve Cornett (boost_at_[hidden])
Date: 2006-02-20 12:46:15
Perhaps I was not clear, plus the ## operator is a trickster. Let's try
this: you can prove to yourself that the ## operators are having no effect
(and are therefore unnecessary) with this sample program below. Compile and
run it both with and without the patch. You will see no change in the
behavior.
#include <stdio.h>
#include "stringize.hpp"
int main()
{
puts(BOOST_PP_STRINGIZE(x));
return 0;
}
So beyond being unnecessary, let me again attempt to convince you that the
## operators are also wrong and therefore undesirable. First let me explain
my motivation. Our tool issues a warning when our end user compiles this
file with our code coverage tool together with Microsoft C++. The reason
for the warning is a long story, but we need it. Other than the warning,
our behavior with the ## operator is exactly the same as Microsoft C++.
Sometimes end users turn on the option that says all warnings are errors,
and then their build fails. So we don't want to bother the end user with
something they have no control over.
Anyway, let's look closely at this line:
# define BOOST_PP_STRINGIZE_A(arg) BOOST_PP_STRINGIZE_B ## (arg)
In BOOST_PP_STRINGIZE_A there is an attempt to join "BOOST_PP_STRINGIZE_B"
with "(" that would result in a single token "BOOST_PP_STRINGIZE_B(". That
does not make sense, this is clearly two separate tokens, an identifier and
a '('. The ## is not really accomplishing anything here. The only effect
of ## here is to make this macro behavior undefined by the C and C++
standards.
The problem is just a little harder to see in BOOST_PP_STRINGIZE_B:
# define BOOST_PP_STRINGIZE_B(arg) BOOST_PP_STRINGIZE_I ## arg
In this case, the argument "arg" is always passed in from BOOST_PP_STRINGIZE
and it always begins with "(". But after that, it is the same story as
before, you cannot join an identifier with a '('.
So I hope you see more clearly what is happening now.
By the way, when I compile the whole boost library with our tool, I see the
warning about ## producing invalid results only here in stringize.hpp.
Regards,
Steve Cornett
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk