Topic: true in preprocessing
Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Mon, 12 Aug 2002 21:14:57 GMT Raw View
On Thu, 8 Aug 2002 13:31:22 GMT, loewis@informatik.hu-berlin.de
(Martin v. L=F6wis) wrote:
>> >>#if true
>It evaluates to true, and the sentence
>
>"Only the first group whose control condition evaluates to true
>(nonzero) is processed."
>
>applies, so the group following the #if is processed.
Indeed the phrase "except for true and false" in 16.1/4 (well, at
least the "except for true") seems to be there for this exact purpose.
But none of the compilers I have access to treat 'true' as '1' in
preprocessing directives.
Can I conclude they are all wrong?
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: loewis@informatik.hu-berlin.de (Martin v. =?iso-8859-1?q?L=F6wis?=)
Date: Tue, 13 Aug 2002 22:56:52 GMT Raw View
Gennaro Prota <gennaro_prota@yahoo.com> writes:
> Indeed the phrase "except for true and false" in 16.1/4 (well, at
> least the "except for true") seems to be there for this exact purpose.
> But none of the compilers I have access to treat 'true' as '1' in
> preprocessing directives.
>
> Can I conclude they are all wrong?
You can conclude that you did not test all current compilers :-)
For
#define foo true
#if foo
#error yes
#else
#error no
#endif
gcc 3.1 gives
a.cc:4:2: #error yes
Most other compilers probably use their historical preprocessor, or
just didn't check the standard when they updated the preprocessor for
C++.
If none of the commercial compilers gets this right, I can only
conclude that the C++ test suites do not cover that case, either.
The plain truth probably is that nobody expects the preprocessor to be
strictly defined.
Regards,
Martin
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Wed, 14 Aug 2002 04:45:09 GMT Raw View
On Tue, 13 Aug 2002 22:56:52 GMT, loewis@informatik.hu-berlin.de
(Martin v. L=F6wis) wrote:
>You can conclude that you did not test all current compilers :-)
Yes. I don't have access to every compiler in the world :-)
>For
>
>#define foo true
>
>#if foo
>#error yes
>#else
>#error no
>#endif
>
>gcc 3.1 gives
>
>a.cc:4:2: #error yes
>
Nice. gcc 2.95.3-5 (cygwin special) gives #error no. I have to update
my compiler, necessarily! ;-)
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: Gennaro Prota <gennaro_prota@yahoo.com>
Date: Mon, 5 Aug 2002 18:20:18 GMT Raw View
Yesterday I was talking with a friend about some preprocessor
idiosyncrasies, like the treatment of the directive
#if true
>From what I've read in some old posts it seems that the intent is to
treat it like a #if 0, but when I went to clause 16 I was quite
surprised. Paragraph 16.1/4 says
"After all replacements due to macro expansion and the defined unary
operator have been performed, all remaining identifiers and
keywords137), except for true and false, are replaced with the
pp-number 0, and then each preprocessing token is converted into a
token."
Note the "except for true and false".
Then it says: "The resulting tokens comprise the controlling constant
expression which is evaluated according to the rules of 5.19 [...]
Each subexpression with type bool is subjected to integral promotion
before processing continues."
Now, since when evaluation occurs the true above is still there (it
has never been substituted) shouldn't it be a subexpression with type
bool converted to 1 by integral promotion?
Please, don't tell me that the preprocessor doesn't know about
keywords etc..etc.. I'm simply after standard text where to see that
the literal true is not treated as a 1.
Thanks in advance,
Genny.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]