if (pointer) command
Jordan Brown
lcc.jbrown at LOCUS.UCLA.EDU
Tue Sep 9 12:26:14 AEST 1986
> From: Brandon Allbery <allbery%ncoast.uucp at BRL.ARPA>
> [ code which used "if(pointer) stmt;" ]
> But if a pointer is 4 bits and an int is 2 bits (some 68000 implementations),
> you'll get spurious failures if the pointer returned by malloc is a multiple
> of 0x10000!
Those are the smallest pointers and ints I've ever seen! But seriously,
K&R never says that the expression in an if is converted to an int.
It says (pg 201)
...the expression is evaluated and it if is non-zero...
While this does not explicitly allow the if(pointer) usage, it can easily
be interpreted to mean that "if(expr)" is equivalent to "if(expr!=0)", which
IS guaranteed to work for pointers (pg 190).
Lots of code would break if this usage was not allowed.
More information about the Comp.unix
mailing list