Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!zephyr.ens.tek.com!uunet!spool.mu.edu!cs.umn.edu!uc!shamash!paul From: paul@u02.svl.cdc.com (Paul Kohlmiller) Newsgroups: comp.std.c Subject: Voids in a comma expression Keywords: voids comma operator Message-ID: <34405@shamash.cdc.com> Date: 21 Jun 91 20:35:40 GMT Sender: usenet@shamash.cdc.com Distribution: usa Lines: 35 This program gets a fatal diagnostic from at least one C compiler but works okay on at least 3 others. extern void foo(int x); main() { int j=3; int i; j=(i=4,foo(i),i++); } The diagnostic claims that ANSI disallows the void expression foo(i) in the command expression. ANSI 3.3.17 claims that the left operand is evaluated as a void. Does this mean the leftmost only? That seems wrong since only the rightmost operand really needs to be non-void. However, the diagnostic says that it is disallowed because of something in section 3.2.2.1 but I can't find it. The ANSI grammar under the comma operator says: expression: assignment-expression expression , assignment-expression which might imply that (i=4,foo(i),i++) is the same as (i=4,foo(i)),i++ /*Did I get that right? */ if this is right then foo(i) is the rightmost operand at some point in time? Maybe? Flipping the positions of i=4 and foo(i) makes it compile okay on all compilers. Paul Kohlmiller CDC disclaimers, etc. -- // Paul H. Kohlmiller // "Cybers, Macs and Mips" // // Control Data Corporation // Internet: paul@robin.svl.cdc.com // // All comments are strictly // America Online: Paul CDC // // my own. // Compuserve: 71170,2064 //