Mail Archives: djgpp/1996/01/10/19:09:28
On Wed, 10 Jan 1996 kagel AT quasar DOT bloomberg DOT com wrote:
> if (!my_pointer)
> my_pointer = (my_struct_t *)malloc( sizeof (my_struct_t) );
>
> Or BETTER CODE but equivalent:
>
> if (my_pointer == (my_struct_t *)NULL)
> ...
You shouldn't need to cast NULL, I don't think...
Either way, even better than that would be:
if (NULL == my_pointer) ...
since this will give you a compiler error if you make a typo and
only use one equal sign. (Otherwise, it is an assignment, which can
cause no end of problems. It's also a PAIN to find, when you do do it.)
/***********************************************************************
* Jesse Morris * cuth AT gryphon DOT ccs DOT brandeis DOT edu * jrmorris AT macalstr DOT edu *
**************** Cuthalion / Sliced Bread *************************
\*********************************/
- Raw text -