expr ? ptr : 0

Morris Keesan keesan at bbncca.ARPA
Tue Feb 7 10:53:30 AEST 1984


----------------------
    Thanks to all who responded to my query.  Please stop sending results.
For those who missed the question, I will recap.  It turns out that the most
recent (previous to myself) maintainer of BBN's C compiler put in some code
to issue warnings about illegal combinations of pointers and integers.  The
?: operator fell into the default case, where the ':' cannot have a pointer
and an integer as operands.  Unfortunately, he forgot the case where the
integer is the constant 0, which is explicitly allowed (Ref. Manual 7.13).
Wondering what could be considered "the constant 0", I requested reports on
the behaviour of other C compilers when compiling expressions where the 0
in the above (in the Subject) expression was replaced with '\0', 0L, and
(short)0.  I got several responses about a few compilers for the VAX, all of
which accepted '\0' (which, it was pointed out, is actually an integer --
ref.man. 7.1), 0, and 0L, and complained about (short)0.  Other responses
were of compilers which were silent, such as the V7 PDP-11 compiler, which
mine is based on.  Reading section 7.1 of the reference manual, one discovers
that (short)0 is not, by definition, a "constant":  "A constant . . . may be
int, long, or double . . . Character constants have type int;"   
    I have decided to allow '\0', 0, and 0L, for consistency with System V and
4.xBSD.  Thanks to all who helped out with research.
-- 
					Morris M. Keesan
					{decvax,linus,wjh12}!bbncca!keesan
					keesan @ BBN-UNIX.ARPA



More information about the Comp.lang.c mailing list