Voids in a comma expression
Paul Kohlmiller
paul at u02.svl.cdc.com
Sat Jun 22 06:35:40 AEST 1991
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 at robin.svl.cdc.com //
// All comments are strictly // America Online: Paul CDC //
// my own. // Compuserve: 71170,2064 //
More information about the Comp.std.c
mailing list