use of if (!cptr) and if (cptr), where cptr is a *
Doug Gwyn
gwyn at smoke.BRL.MIL
Wed Jul 19 15:56:31 AEST 1989
In article <93 at microsoft.UUCP> paulc at microsoft.UUCP (Paul Canniff 2/1011) writes:
>It will break if NULL != 0.
malloc() is required to return a null pointer when it cannot allocate
the storage. Having stashed that into a variable named "sptr", the
test (!sptr) is required to correctly determine whether or not sptr
is a null pointer, so the whole procedure is correct.
What NULL may be defined as in some header is irrelevant here. Anyway,
in standard headers that define NULL, NULL must be defined to be a
valid generic null pointer (0 or (void*)0 for Standard C). There are
some known bogus C implementations that define NULL as 0L or other
warped flavors of 0, but I've never heard of one so far gone as to
define NULL to be something totally unusable as a null pointer constant.
More information about the Comp.lang.c
mailing list