Is "if (!pointer)" as portable as "if (pointer == NULL)" ???

Larry Jones scjones at sdrc.UUCP
Thu Apr 12 07:59:51 AEST 1990


In article <656 at hades.OZ>, greyham at hades.OZ (Greyham Stoney) writes:
> Is this correct?. Can I just do:
> 	if (buffer) free(buffer)
> And stuff like that?.

Yes.  A null pointer is guaranteed to compare equal to zero, so
if (ptr) and if (!ptr) are completely portable.  Many will debate
whether they are stylistically good or bad, but they definitely
are portable.
----
Larry Jones                         UUCP: uunet!sdrc!scjones
SDRC                                      scjones at SDRC.UU.NET
2000 Eastman Dr.                    BIX:  ltl
Milford, OH  45150-2789             AT&T: (513) 576-2070
"You know how Einstein got bad grades as a kid?  Well MINE are even WORSE!"
-Calvin



More information about the Comp.lang.c mailing list