Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!apple!bloom-beacon!adam.pika.mit.edu!scs From: scs@adam.pika.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: malloc & tc. Keywords: malloc, turboc Message-ID: <11399@bloom-beacon.MIT.EDU> Date: 13 May 89 19:20:34 GMT References: <8283@techunix.BITNET> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: scs@adam.pika.mit.edu (Steve Summit) Lines: 30 In article <8283@techunix.BITNET> ssreefc@techunix.BITNET (florin coter) writes: > extern char a[1000][50]; /* !!! */ > if( ( *p=malloc( (unsigned)30000 ) ) == NULL ) > puuts( "no space" ); I suspect that the "*p=" and "puuts" are typos; I suspect that the "extern" on the declaration of a is not. Being external, this declaration is what is called a "declaring instance," not a "defining instance." It allocates no space. Since a is not used, the declaration is essentially discarded, ~50K is not set aside, and sufficient memory remains to satisfy the malloc(30000) request. (If a were used, you would get an "undefined symbol" error at link time, noting the absence of a defining instance.) Malloc is an extremely important and oft-used routine. Although subtle bugs are occasionally noted in new implementations, it is quite unlikely that a non-NULL pointer to in-use memory could ever be returned during an out-of-memory condition (or under any other circumstances, for that matter). Malloc has to return NULL when there's no memory. That's its job. Steve Summit scs@adam.pika.mit.edu P.S. Please be very careful about typos in source postings, incorporating the C source file directly into your text editor while composing the message, if possible. Otherwise people may correct your typos and overlook the real problem (which I don't claim to have discovered either, because the posting is still a bit sketchy).