Voids in a comma expression

Norman Diamond diamond at jit533.swstokyo.dec.com
Sat Jun 22 16:14:14 AEST 1991


In article <34405 at shamash.cdc.com> paul at u02.svl.cdc.com (Paul Kohlmiller) writes:
>extern void foo(int x);
>j=(i=4,foo(i),i++);
>The diagnostic claims that ANSI disallows the void expression foo(i) in the
>command expression.

The diagnostic is wrong.

>ANSI 3.3.17 claims that the left operand is evaluated as
>a void. Does this mean the leftmost only?

It does.  In the expression   i=4,foo(i)
  i=4      is evaluated as a void;
  foo(i)   is evaluated, and the value of foo(i) is taken to be the value
    of i=4,foo(i).  The compiler seems to be confused because this value
    is void.  The value cannot be used in any way, but you're not using it.
    The value cannot be converted implicitly or explicity except to void
    (section 3.2.2.2), i.e. there is no prohibition against an implicit
    conversion to another void.

In the expression   i=4,foo(i),i++
  i=4,foo(i)   is evaluated as a void.  We just did this.
  i++          is evaluated and the result is the result of the expression.

>That seems wrong since only the rightmost operand really needs to be non-void.

The rightmost operand does not really need to be non-void.  If it did, then
the diagnostic would have been right.
--
Norman Diamond       diamond at tkov50.enet.dec.com
If this were the company's opinion, I wouldn't be allowed to post it.
Permission is granted to feel this signature, but not to look at it.



More information about the Comp.std.c mailing list