From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marco Franzen To: gcc@gcc.gnu.org Subject: (C and C++:) conditional (?:) type balancing wrt comma op and 0 denoting null Date: Mon, 18 Sep 2000 07:01:00 -0000 Message-id: <00091814310100.00496@Maidavale> X-SW-Source: 2000-09/msg00399.html 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