C Compiler bug (?: operator)
W. H. Pollock x4575 3S235
whp at cbnap.UUCP
Thu Jul 31 23:12:59 AEST 1986
In article <134 at sas.UUCP> jcz at sas.UUCP (Carl Zeigler) writes:
>
> > > void f3(which)
> > > {
> > > extern void f1(),f2();
> > > which?f1():f2();
> > > }
> > > cc(1) gives an "incompatible types" error.
> >
> > As it should. The only thing you're allowed to do with void values
> > is throw them away.
>
>Scan again, Andrew, the (void) values are being thrown away.
The void values are not thrown away! Remember that (A?B:C) is an
expression *returning a value*. C is giving the error because it can't
determine the type of the return value. This is clearer in the following:
void f3(which)
{
int f1();
void f2();
int foo;
...
foo = which?f1():f2();
...
}
which results in the same error message, for the same reason. Another
example:
f4()
{
...
return ((void) expression);
}
Note it doesn't mater what use is made of the return value (in the original
example it is thrown on the floor, which is what probably confused some
people).
More information about the Comp.lang.c
mailing list