public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* (C and C++:) conditional (?:) type balancing wrt comma op and 0 denoting null
@ 2000-09-18  7:01 Marco Franzen
  0 siblings, 0 replies; only message in thread
From: Marco Franzen @ 2000-09-18  7:01 UTC (permalink / raw)
  To: gcc

I am not sure if this is a bug in GCC. 
It not, I would argue it were a deficiency in the language definitions
(both C and C++).

I found this behaviour with
gcc version 2.96 20000814 (experimental)
but it is still present with
gcc version 2.96 20000917 (experimental)
(as on < http://www.codesourcery.com/gcc-compile.shtml >).

The following two programs should be either both correct or both
incorrect, but GCC judges them differently.

=========================
char c;
int fun () { return 42; }
int main () { 1 ? (fun(),0) : &c; }
=========================

=========================
char c;
int main () { 1 ? (42,0) : &c; }
=========================

GCC's C frontend accepts both but gives a warning (only) for the first. The
C++ frontend diagnoses basically the same but as an error and accepts only
the second program (without any warning).

Obviously, the `0' is meant to denote a null pointer but is taken as an
integer in the first program (only). Why does that depend on the lhs
argument to the comma operator? I think it shouldn't.

Cheers,

Marco
-----------------------------------------------------------------
This email is confidential and intended solely for the use of the
individual to whom it is addressed.
Any views or opinions presented are solely those of the author
and do not necessarily represent those of Thyron Limited.
If you are not the intended recipient then please be advised
that you have received this email in error and that any use,
dissemination, forwarding, printing or copying of this email
is strictly prohibited.
If you have received this email in error, please notify the
Thyron IT Administrator on +44 (0)1923 236 050 or
send an email to mail-admin@thyron.com.
Thank You

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2000-09-18  7:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-18  7:01 (C and C++:) conditional (?:) type balancing wrt comma op and 0 denoting null Marco Franzen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).