Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cmcl2!yale!mintaka!snorkelwacker.mit.edu!apple!agate!violet.berkeley.edu!lindahl From: lindahl@violet.berkeley.edu (Ken Lindahl 642-0866) Newsgroups: comp.sys.mac.programmer Subject: Re: Novice question about malloc() in Think C Message-ID: <1991Feb25.183334.18500@agate.berkeley.edu> Date: 25 Feb 91 18:33:34 GMT References: <1991Feb25.103404.3662@Neon.Stanford.EDU> <12591@helios.TAMU.EDU> Sender: usenet@agate.berkeley.edu (USENET Administrator) Distribution: usa Organization: University of California, Berkeley Lines: 35 Well, I guess everybody should have to apologize at least once for posting a blank followup, so here it is: I'm sorry. The fingers are faster than the brain, sometimes. In article <12591@helios.TAMU.EDU> n138ct@tamuts.tamu.edu (Brent Burton) writes: >Your code is perfect. So why doesn't it work? :-) >I have had this problem too. I don't know what it is, but I looked at >the alloc.c file and tried to figure it out. It's been a while, but I think >it returns null if it can't get the block and also if the block requested >is under a certain size. Don't quote me on this nor flame me, people. Well, I'm quoting you, but hopefully you won't think this is a flame. The original posting did not show the declaration for malloc() and this is critical. In Think C 4.0 and later, the correct declaration is void *malloc(); In Think C 3.x and in most UNIX implementations, the correct declaration is char *malloc(); I know from experience that if you try the latter declaration in Think C 4.x, you will get the behavior described above. The best way to get the correct declaration is to #include in any file containing invocations of malloc() or any of its friends(calloc(), free(), realloc(), ...). Ken Lindahl lindahl@violet.berkeley.edu Advanced Technology Planning, Information Systems and Technology University of California at Berkeley