Compiler bug

Mark A Terribile mat at mole-end.UUCP
Tue Dec 20 13:39:19 AEST 1988


> -------- foo.c --------
> int foo = 1 && 0;
> ------ end foo.c ------
> 
> On a Bsd 4.3 VAX 785, cc complains :
> "foo.c", line 1: illegal initialization
> 
> On a Xenix286 intel sys310, cc compiles it nicely, but lint
> (1)  warning: constant in conditional context
> (1)  illegal initialization

Actually, the compilers are right, more or less.  According to the reference
manual in the back of K&R (I haven't yet got the dpANS for C) && and || are
NOT among the operators which may be used to compose constant expressions,
so the messages about illegal initializations make sense.  The warning about
the illegal constant sounds bogus; I suspect that the Xenix compiler is trying
to tell you that it thinks that if you really mean that you should do it with
the preprocessor.

Now then, how to do what you want to do?  Well, among the operators that
*can* be used to compose constant expressions is  ?: .

For  a && b , use  a ? b : 0 .
For  a || b , use  a ? 1 : b .

The Xenix compiler will probably still bless you with a warning.
-- 

(This man's opinions are his own.)
>From mole-end				Mark Terribile



More information about the Comp.lang.c mailing list