From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,cb40752a27f3d651 X-Google-Attributes: gid1164f8,public X-Google-Thread: fee84,cb40752a27f3d651 X-Google-Attributes: gidfee84,public X-Google-Thread: 1014db,cb40752a27f3d651 X-Google-Attributes: gid1014db,public From: Noone Really Subject: Re: comma operator: C compiler bug or bogus usage? Date: 1999/04/15 Message-ID: <3716AF0B.A8CC1C04@earthlink.net>#1/1 X-Deja-AN: 466983509 Content-Transfer-Encoding: 7bit References: <7f567v$sp1$1@news.iastate.edu> X-Posted-Path-Was: not-for-mail Content-Type: text/plain; charset=us-ascii X-ELN-Date: 16 Apr 1999 03:30:25 GMT X-ELN-Insert-Date: Thu Apr 15 20:35:09 1999 Organization: EarthLink Network, Inc. Mime-Version: 1.0 Newsgroups: comp.lang.c,comp.unix.osf.osf1,comp.sys.dec 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). ---