Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!rochester!kodak!ispd-newsserver!ism.isc.com!bud.sos.ivy.isc.com!willcr From: willcr@bud.sos.ivy.isc.com (Will Crowder) Newsgroups: comp.lang.c Subject: Re: Pointer and integer addition Message-ID: <1991Apr11.173431.15547@ism.isc.com> Date: 11 Apr 91 17:34:31 GMT References: <8334@umd5.umd.edu> <15631@smoke.brl.mil> <4205@rwthinf.UUCP> Sender: usenet@ism.isc.com (Ism Usenet News) Reply-To: willcr@ivy.isc.com Followup-To: comp.lang.c Organization: Interactive Systems Corp. Lines: 25 In article <4205@rwthinf.UUCP>, berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) writes: |> In article <15631@smoke.brl.mil> gwyn@smoke.brl.mil (Doug Gwyn) writes: |> >In article <8334@umd5.umd.edu> dzoey@terminus.umd.edu (Joe Herman) writes: |> >>fooptr = (char *) fooptr + fooptr->recsize; |> |> >This (almost) should have worked. You also need to convert back to |> >the proper pointer type before the assignment: |> |> > fooptr = (struct foo *) ((char *) fooptr + fooptr->recsize); |> |> No, not needed, the cast is implicit. But will result in a compiler warning on most compilers. It also makes it quite clear what is going on. You cannot blithely assign one pointer type to another without expecting some kind of complaint from the compiler. |> -- |> Stephen R. van den Berg. -------------------------------------------------------------------------------- Will Crowder, MTS | "I was gratified to be able to answer promptly, (willcr@ivy.isc.com) | and I did: I said I didn't know." INTERACTIVE Systems Corp. | -- Mark Twain