Xref: utzoo comp.sys.mac.programmer:5327 comp.sys.mac:29447 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!portal!cup.portal.com!fiver From: fiver@cup.portal.com (Kevin D Dack) Newsgroups: comp.sys.mac.programmer,comp.sys.mac Subject: Re: LSC3.0 brain damage Message-ID: <16614@cup.portal.com> Date: 3 Apr 89 02:15:49 GMT References: <1704@ncar.ucar.edu> <28652@ucbvax.BERKELEY.EDU> Distribution: usa Organization: The Portal System (TM) Lines: 25 > This is _not_ legal C. The correct program follows: > > #include > #include > main() { > char *ptr; > int max= 400; > > ptr= (char *)malloc(500); > while (max--){ > fprintf (stderr,"ptr= %d\n", (int) ptr); > ptr++; > } > > } Actually, it's more likely to be portable if "malloc" is declared first, rather than allowed to default to "int" and then cast. The way it is above, you're liable to get the lower 16 bits of the return value sign-extended. (I got bit by this in someone else's code that I was porting from a 386 to a 286. Gack, I know, but this was at work and I had no choice--at least it was Xenix and not MS-DOS...) Kevin Dack fiver@cup.portal.com