Date: Sun, 14 Jan 1996 11:28:15 +0200 (IST) From: Eli Zaretskii To: "Eric J. Korpela" Cc: djgpp AT delorie DOT com Subject: Re: (none) On 11 Jan 1996, Eric J. Korpela wrote: > In article , 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) > > Is this really better? Could option 1 fail? I thought the C standard > guaranteed that the top option would work. Yes, it *is* better. ANSI C says that the null pointer (for any type) is a zero cast to a pointer to that type, but it doesn't guarantee that the bit pattern for the null pointer is all-zero (so that !null_ptr is true). So you could write `if (my_pointer == 0)' (because the compiler automatically will cast 0 to the pointer type), but `if (!my_pointer)' may not work on some odd architectures.