Xref: utzoo comp.sys.mac.programmer:5336 comp.sys.mac:29466 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!ukma!tut.cis.ohio-state.edu!osu-cis!att!ihlpe!kah120 From: kah120@ihlpe.ATT.COM (452is-Heitke) Newsgroups: comp.sys.mac.programmer,comp.sys.mac Subject: Re: LSC3.0 brain damage Keywords: stdio, pointers Message-ID: <4642@ihlpe.ATT.COM> Date: 3 Apr 89 15:47:20 GMT References: <1704@ncar.ucar.edu> Distribution: usa Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 32 In article <1704@ncar.ucar.edu>, bill@hao.ucar.edu (Bill Roberts) writes: > Below is a simple code segment that I was trying to use on a Mac+ using > LSC 3.0. The problem is that the printed value of ptr never increments. It > always stays the same! I move this code over to a Sun4 and it works as one > would expect! What gives? Anyone else run into this problem? > > #include > #include > #include > main() > { > char *ptr; > int max= 400; > > if ((ptr= (char *)malloc(500)) == NULL){ > fprintf (stderr,"ERROR: malloc() \n"); > exit(); > } > while (max--) > fprintf (stderr,"ptr= %d\n", ptr++); > > } The ptr is actually a 32 bit variable and the %d in the printf format will only print the value of a 16 bit quantity. In this case it happens to be the upper 16 bits of the address which doesn't change. To print the actual pointer value use %ld or %lx (for hex). > > --Bill Ken Heitke