Path: utzoo!utgpu!watmath!clyde!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c Subject: Re: Compiler bug Summary: Remember, && can't const Message-ID: <126@mole-end.UUCP> Date: 20 Dec 88 03:39:19 GMT References: <4279@freja.diku.dk> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 30 > -------- 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