Topic: Ambiguous Footnote on #if Description
Author: "Jim Cobban" <Jim.Cobban.jcobban@nt.com>
Date: 1998/08/13 Raw View
In the draft standard there is a footnote explaining the restrictions on
the constant expression in a #if which read:
136) Because the controlling constant expression is
evaluated during translation phase 4, all identifiers
either are or are not macro names - there simply are
no keywords, enumeration constants, and so on.
Thank you for pointing this out. I do find the text of this point strange.
It says "all identifiers either are or are not macro names". That is a
tautology. The set includes all possible identifiers and therefore
contradicts the following phrase. "keywords, enumeration constants, and
so on" are not macro names and therefore they are INCLUDED in the set of
permitted identifiers in the defining phrase.
What was the intent of including the text "either are or are not"? That is
if the intention is that only macro names can be used in these expressions
why doesn't it just say that.
--
Jim Cobban | jcobban@nortel.ca | Phone: (613) 763-8013
Nortel (MCS) | | FAX: (613) 763-5199
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/08/13 Raw View
"Jim Cobban" <Jim.Cobban.jcobban@nt.com> writes:
>In the draft standard there is a footnote explaining the restrictions on
>the constant expression in a #if which read:
> 136) Because the controlling constant expression is
> evaluated during translation phase 4, all identifiers
> either are or are not macro names - there simply are
> no keywords, enumeration constants, and so on.
>Thank you for pointing this out. I do find the text of this point strange.
>It says "all identifiers either are or are not macro names". That is a
>tautology. The set includes all possible identifiers and therefore
>contradicts the following phrase. "keywords, enumeration constants, and
>so on" are not macro names and therefore they are INCLUDED in the set of
>permitted identifiers in the defining phrase.
>What was the intent of including the text "either are or are not"? That is
>if the intention is that only macro names can be used in these expressions
>why doesn't it just say that.
It's a note, not normative text, and is intended to help
explain the significance of what preceeded.
The phases of translation require that the expression in a #if
be evaluated before keywords and types are recognized. Thus,
during this phase (except for preprocessor keywords like
"defined"), an identifier is either the name of a defined macro
or it isn't. If not, it is replaced by a literal 0 (zero). That is,
you can use names that are not defined as macro names, as long as
you realize that they are equivalent to zero.
Suppose you write this:
enum { size = 4 };
#if size == sizeof(int)
...
In the second line, the identifiers "size", "sizeof" and "int"
are not the names of macros, and are not preprocessor keywords.
Therefore, the line is interpreted as if you had written
#if 0 == 0(0) // syntax error
That is what the note is attempting to point out.
(Some compilers provide an extension where they recognize
sizeof and the built-in type names, but that isn't, and
never has been, standard.)
--
Steve Clamage, stephen.clamage@sun.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/08/13 Raw View
Jim Cobban wrote:
>
> In the draft standard there is a footnote explaining the restrictions on
> the constant expression in a #if which read:
>
> 136) Because the controlling constant expression is
> evaluated during translation phase 4, all identifiers
> either are or are not macro names - there simply are
> no keywords, enumeration constants, and so on.
>
> Thank you for pointing this out. I do find the text of this point strange.
> It says "all identifiers either are or are not macro names". That is a
> tautology.
It says that there is only one way of classifying identifiers: they are
macro names or they are not. Nothing else need be considered.
> The set includes all possible identifiers and therefore
> contradicts the following phrase. "keywords, enumeration constants, and
> so on" are not macro names and therefore they are INCLUDED in the set of
> permitted identifiers in the defining phrase.
No, that phrase reminds us that even though we're used to thinking of
keywords, etc. as names that we cannot give other meanings to, the
preprocessor does not view them that way. You are free to create a macro
named sizeof, precisely because it is not a macro name. You don't have
to worry that it's the name of a keyword: that's OK with the
preprocessor.
I do think that this is a bit obscure. But if there's a way to read
something that leads to a contradiction and a way to read it that does
not, choose the one that does not lead to a contradiction. And remember,
too, that footnotes are not normative -- they're supposed to clarify,
but if they contradict what the text says, the text wins.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: AllanW@my-dejanews.com
Date: 1998/08/14 Raw View
In article <6qv08b$6eu@bcarh8ab.bnr.ca>,
"Jim Cobban" <Jim.Cobban.jcobban@nt.com> wrote:
>
> In the draft standard there is a footnote explaining the restrictions on
> the constant expression in a #if which read:
>
> 136) Because the controlling constant expression is
> evaluated during translation phase 4, all identifiers
> either are or are not macro names - there simply are
> no keywords, enumeration constants, and so on.
>
> Thank you for pointing this out. I do find the text of this point strange.
> It says "all identifiers either are or are not macro names". That is a
> tautology.
It's kind of funny, when you put it that way.
The phrase is an English-language idiom. Contrast it to a remark
made to Joe, who was standing outside of a restaurant:
"Joe, you either are or are not hungry -- move out of the way!"
In Joe's case, we mean that Joe should go in if he's hungry, or
go away if he's not. In the C++ standard, we mean that by the time
we get to translation phase 4, the C++ compiler can tell if an
identifier is a macro name or not -- without considering (yet)
whether the name could be a C++ keyword such as int or typedef.
> The set includes all possible identifiers and therefore
> contradicts the following phrase. "keywords, enumeration constants, and
> so on" are not macro names and therefore they are INCLUDED in the set of
> permitted identifiers in the defining phrase.
That's right, for the reasons I stated above. Thus, it's legal
to do this:
#define short long
// ...
#ifdef short
char warning[] = "Warning: short was re-defined as long!\n";
#endif
Note that the macro name (short) is spelled the same as a C++ keyword.
But this section of the spec makes it legal to use short as a macro
name anyway.
> What was the intent of including the text "either are or are not"? That is
> if the intention is that only macro names can be used in these expressions
> why doesn't it just say that.
Since the compiler "knows" if the name is a macro, it can include or
exclude the next section of code. There's no guesswork involved.
--
AllanW@my-dejanews.com is a "Spam Magnet" -- never read.
Please reply in USENET only, sorry.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: David R Tribble <david.tribble@noSPAM.central.beasys.com>
Date: 1998/08/14 Raw View
Jim Cobban wrote:
>> In the draft standard there is a footnote explaining the restrictions
>> on the constant expression in a #if which read:
>>
>> 136) Because the controlling constant expression is
>> evaluated during translation phase 4, all identifiers
>> either are or are not macro names - there simply are
>> no keywords, enumeration constants, and so on.
>>
>> Thank you for pointing this out. I do find the text of this point
>> strange. It says "all identifiers either are or are not macro names".
>> That is a tautology.
Pete Becker wrote:
> It says that there is only one way of classifying identifiers: they
> are macro names or they are not. Nothing else need be considered.
Does this include the alternate spelling keywords 'and', 'or', and
so forth? For example, what does the pp-token 'and' look like
during phase 4 for the following snippet?:
#if WORDSIZE > 2 and USE_ASCII
...
#endif
-- David R. Tribble, dtribble@technologist.com --
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: stephen.clamage@sun.com (Steve Clamage)
Date: 1998/08/14 Raw View
David R Tribble <david.tribble@noSPAM.central.beasys.com> writes:
>Pete Becker wrote:
>> It says that there is only one way of classifying identifiers: they
>> are macro names or they are not. Nothing else need be considered.
>
>Does this include the alternate spelling keywords 'and', 'or', and
>so forth? For example, what does the pp-token 'and' look like
>during phase 4 for the following snippet?:
>
> #if WORDSIZE > 2 and USE_ASCII
> ...
> #endif
The alternative spellings are just that: different ways to spell
the same token. During token recognition (phase 3) "and" is
treated as if written "&&", so you should get the same result as
#if WORDSIZE > 2 && USE_ASCII
--
Steve Clamage, stephen.clamage@sun.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Pete Becker <petebecker@acm.org>
Date: 1998/08/15 Raw View
David R Tribble wrote:
> Jim Cobban wrote:
> >> In the draft standard there is a footnote explaining the restrictions
> >> on the constant expression in a #if which read:
> >> 136) Because the controlling constant expression is
> >> evaluated during translation phase 4, all identifiers
> >> either are or are not macro names - there simply are
> >> no keywords, enumeration constants, and so on.
> >> Thank you for pointing this out. I do find the text of this point
> >> strange. It says "all identifiers either are or are not macro names".
> >> That is a tautology.
>
> Pete Becker wrote:
> > It says that there is only one way of classifying identifiers: they
> > are macro names or they are not. Nothing else need be considered.
> Does this include the alternate spelling keywords 'and', 'or', and
> so forth? For example, what does the pp-token 'and' look like
> during phase 4 for the following snippet?:
> #if WORDSIZE > 2 and USE_ASCII
> ...
> #endif
It is a footnote, which is not normative. It is intended to clarify the
text that it is a note too. If you want to get into legalisms of what
the standard means you must refer to the normative parts, not the
non-normative ones.
--
Pete Becker
Dinkumware, Ltd.
http://www.dinkumware.com
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]