zaimoni@zaimoni.com writes:
Quote:
I've already calculated that the following are valid and should not
error, as both just end up with the character literal 'A' being their
control expression. The unspecified value of the char* pointing to
the string literal is eliminated during evaluation, so the fact it is
unknowable doesn't matter. ('A' is assumed not be to mapped to NUL.)
'A' cannot be equal to 0 (NUL) in a conforming implementation.
Quote:
[GCC 4.2.1 accepts the first, and inconsistently considers *"A" to be
an invalid control expression.]
gcc 3.4.4 and 4.2.4 reject all of your examples.
Quote:
#if "A"[0]
#else
#error "A"[0] is false
#endif
>
#if *"A"
#else
#error *"A"[0] is false
#endif
Both of these are constraint violations, requiring diagnostics.
C99 6.10.1p1:
The expression that controls conditional inclusion shall be an
integer constant expression except that [...]
This is a constraint, so violating it requires a diagnostic.
C99 6.6p6 defines "integer constant expression"; it may not contain a
string literal.
Quote:
C99 6.4.4.1 does not clearly state that an integer literal is an
object, so this should be invalid as the requirements of the address-
of operator & are imposed even though neither * nor & are evaluated.
>
#if *&0
#error *&0 is true
#endif
An integer constant is not an lvalue, so &0 is a constraint violation.
Quote:
C99 6.4.5p5 goes into some detail regarding the exact layout of a
string literal, so it is clear that a string literal points to an
object
No, a string literal does not point to an object. If it did,
sizeof "hello"
would yield sizeof(char*); instead, it yields 6, the size of the array
object that corresponds to the string literal.
Quote:
-- at conceptual translation phase 7, three conceptual stages
after preprocessing (conceptual stage 4). Does an implementation have
license to assume said layout during preprocessing? Alternately, is
the following required to be invalid even though **&"A" must be
accepted at compile-time? :
>
#if **&"A"
#else
#error **&"A" is false
#endif
>
If an implementation has license to accept the above example, is there
some way to infer that it is actually required to accept the above
example?
As above, the example violates a constraint by attempting to use a
string literal as part of an expression in a context that requires an
integer constant expression. A conforming compiler must issue a
diagnostic. Once it's done so, it may, but is not required to,
continue to process the translation unit.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"