pointers, tests, casts

Guy Harris guy at auspex.UUCP
Thu Nov 24 03:50:42 AEST 1988


>In assignments, a 0 or NULL is cast implicitly to the correct pointer
>type (I think, please correct me if I'm wrong).

This is correct.

>What about the '==' comparison above?  Would "(ptr == 0)" get evaluated
>correctly?

In any valid C implementation, it will be.  The compiler certainly knows
enough to do the implicit conversion, just as it does in the case of an
assignment.

>Or to push it a bit further, what about the VAX-ish standard (like
>*(char *)0 = 0 ;-) "(!ptr)"?  I realize that it is probably better to
>explicitly cast & compare, but it did kind of make sense to say "if
>(!ptr)..."

This will also work in any valid C implementation.



More information about the Comp.lang.c mailing list