Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!zaphod.mps.ohio-state.edu!think.com!huxley!steve From: steve@huxley.huxley.bitstream.com (Steve Stein) Newsgroups: comp.sys.mac.programmer Subject: Re: Novice question about malloc() in Think C Message-ID: Date: 25 Feb 91 20:37:36 GMT References: <1991Feb25.103404.3662@Neon.Stanford.EDU> <12591@helios.TAMU.EDU> Sender: steve@huxley.UUCP Reply-To: (Stephen Z. Stein) Distribution: usa Organization: Bitstream, Inc. Lines: 30 In-reply-to: n138ct@tamuts.tamu.edu's message of 25 Feb 91 17:34:33 GMT In article <12591@helios.TAMU.EDU> n138ct@tamuts.tamu.edu (Brent Burton) writes: > Your code is perfect. Wrong. > I have had this problem too. Because you make the same mistake, I think. The problem the original poster (to whom I replied by eMail) had was, I believe, that malloc was returning some strange values. I am virtually certain he was having this error because he forgot to #include like it says to in the friendly manual. Leaving this out has the effect of NOT declaring malloc before it's used. THINK C (like C compilers everywhere) will then assume that malloc will return an int, which in THINK C is a two byte value. This value will get sign-extended to a long when it is typecast to a pointer. This is not a problem on systems where sizeof(int)==sizeof(int *). SO: Lesson 1: Read the friendly manual. Lesson 2: Pay the syntax! - Steve Stein