TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jerry Coffin
from: Bob Stout
date: 2003-09-11 21:32:58
subject: Re: Pointers

From: rbs{at}snippets.org
To: c_echo{at}yahoogroups.com

On Thu, 11 Sep 2003, Jerry Coffin wrote:

> Simple: by getting into the habit of putting them together, you don't
> accidentally do one part without the other.  Just for example, if you write:
>
> x = malloc(somesize);
>
> it's easy to forget to add the:
>
> if ( x == NULL)
>          // allocation failed.
>
> OTOH, if you always write it as:
>
> if ( NULL == (x=malloc(somesize)))
>          // allocation failed
>
> you're much less likely to forget.

Arguably even better are...

	assert(x = malloc(somesize));

...or...

#define MALLOC(ptr,size) if(NULL==(ptr=malloc(size))) abort()

	MALLOC(x, somesize);

-------------------------------------------------------------
Consulting: http://www.MicroFirm.biz/
Web graphics development: http://Image-Magicians.com/
Software archives: http://snippets.org/snippets/
Audio and loudspeaker design:
  http://LDSG.snippets.org/
  http://www.diyspeakers.net/

--- SoupGate-Win32 v1.05
* Origin: rbs{at}snippets.org (2:292/516.666)
SEEN-BY: 633/267 270
@PATH: 292/516 854 140/1 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.