Correct and entirely safe.
if() expects an integer expression,
Not true. 'if' expects to be controlled by an expression of
*scalar* type (basically, anything except an aggregate).
which conventionally would be
the result yielded by a relational operator such as !=. This
result will either by zero (false) or non-zero (true).
Sort of. 'if' compares its controlling expression to 0. If
it's not equal to 0, the body of the 'if' is executed. Otherwise,
the body of the 'if' is *not* executed. That's all.
For example,
if (foo)
is exactly equivalent to
if ((foo) != 0)
[you see now why aggregate types are not permitted in 'if'
conditions]. So, specifically,
if (pFoo)
if ((pFoo) != 0)
are equivalent expressions. And since 0 is in a pointer
context here, it's equivalent to a null pointer of type 'char *';
that is,
if (pFoo)
if ((pFoo) != NULL)
if ((pFoo) != (char*)0)
are also all equivalent. And of course they all do what you'd
expect.
If if() is supplied with a pointer expression this causes an
implicit pointer-to-integer conversion.
Nonsense. There is no "implicit pointer-to-integer conversion."
Ever. Under any circumstances. The language specifically
forbids it. The only implicit conversions are from pointers
to other pointer types, or from arrays to pointers, or between
different arithmetic types. That's it. (Unless I missed one.)
-Arthur