Pointer and integer addition

Will Crowder willcr at bud.sos.ivy.isc.com
Fri Apr 12 03:34:31 AEST 1991


In article <4205 at rwthinf.UUCP>, berg at marvin.e17.physik.tu-muenchen.de
(Stephen R. van den Berg) writes:

|> In article <15631 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
|> >In article <8334 at umd5.umd.edu> dzoey at 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 at ivy.isc.com)         |  and I did: I said I didn't know."
INTERACTIVE Systems Corp.    |		-- Mark Twain



More information about the Comp.lang.c mailing list