Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!jarthur!petunia!news From: rcfische@polyslo.CalPoly.EDU (Ray Fischer) Newsgroups: comp.sys.mac.programmer Subject: Re: Help with bad calloc() call in THINK C 4.02 Message-ID: <26f7f672.65b2@petunia.CalPoly.EDU> Date: 19 Sep 90 22:51:30 GMT References: <26250@cs.yale.edu> Organization: Cal Poly State Univ,CSC Dept,San Luis Obispo,CA 93407 Lines: 24 tarr-michael@CS.YALE.EDU (michael tarr) writes ... >For some reason using THINK C 4.02 the following calloc (at the end of the >code segment) breaks. It returns a pointer that is not really valid (but not >NULL). Here are the data structures used: I've not copied your code in this reply, but nowhere do I see either a #include or a void *calloc(); With Think C (and possibly other C compilers) a definition for the calloc (and alloc, et al) function is required or you will get bad results. The reason is that the default return value for a function is an int. In Think C an int is just 16 bits. Thus, without any declaration to the contrary, Think C will take the 32-bit address returned, expand the low-order 16-bits to 32 bits, then assign that value to your pointer. The solution is simply to tell the compiler that calloc returns a 32-bit result. Ray Fischer rcfische@polyslo.calpoly.edu