From: Noone Really <nooneatnowhere@earthlink.net>
Subject: Re: comma operator: C compiler bug or bogus usage?
Date: 1999/04/15 [thread overview]
Message-ID: <3716AF0B.A8CC1C04@earthlink.net> (raw)
In-Reply-To: 7f567v$sp1$1@news.iastate.edu
John Hascall wrote:
> Is the result of:
>
> constant-expression comma-operator constant-expression
>
> still a constant-expression or not? If not, why not (and it
No.
> seems to me this is the only operator with this property?)
Actually that depends on what exactly you mean. "hello"[0] is not a
constant expression either, even though 'h' and "hello" both are (the
first is integral constant expression and the second is pointer constant
expression). However, except for the comma operator and operators with
possible side effects, a diagnostic is not required and an
implementation may, at its discretion, accept other forms.
It matters in very few places. One you have discovered, the other is
exemplified by the fact that (void*)(0,0) is not a null pointer
constant. The latter again rarely matters because an implementation
gets to choose (but has to document) what (void*)(0,0) becomes, except
in the one context exemplified by the following
int main(void) {
int a[3];
*(0? (void*) (0,0) : a) = 0;
return a[0];
}
is invalid and must get a diagnostic, even though the form with (0,0)
replaced by 0 is perfectly valid C.
>
> John
> PS, FWIW, gcc accepts both of these and produces the 'expected' results
Old versions of gcc, and current versions if you do not ask it to be an
ANSI C compiler (you need the -pedantic switch).
---
next prev parent reply other threads:[~1999-04-15 4:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-04-15 4:00 comma operator: C compiler bug or bogus usage? John Hascall
1999-04-15 4:00 ` Noone Really [this message]
1999-04-15 4:00 ` Joerg Czeranski
1999-04-15 4:00 ` Will Rose
1999-04-15 4:00 ` Lawrence Kirby
1999-04-15 4:00 ` Venkat
1999-04-15 4:00 ` Casper H.S. Dik - Network Security Engineer
1999-04-15 4:00 ` Kaz Kylheku
1999-04-15 4:00 ` John Hascall
1999-04-15 4:00 ` Kaz Kylheku
1999-04-16 4:00 ` Lawrence Kirby
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox