Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!wuarchive!sdd.hp.com!uakari.primate.wisc.edu!aplcen!boingo.med.jhu.edu!haven!umd5!terminus.umd.edu!dzoey From: dzoey@terminus.umd.edu (Joe Herman) Newsgroups: comp.lang.c Subject: Pointer and integer addition Message-ID: <8334@umd5.umd.edu> Date: 29 Mar 91 00:09:44 GMT Sender: news@umd5.umd.edu Organization: University of Maryland DOSIP-CSC Lines: 42 Originator: dzoey@terminus.umd.edu Hello, I have a section of code that scans through a block of variable length records. The structure looks more or less like this: struct foo { unsigned short recsize; unsigned short num; char info [24]; byte flags; char filename[1] }; Where, foo.filename is a placeholder for a variable length string. After I process one record, I'd like to just increment the pointer to point to the next record. What I'd like to do is: fooptr += fooptr->recsize; However, the compiler I'm using increments the pointer by recsize * sizeof (struct foo). This is probably correct. Next, I tried fooptr = (char *) fooptr + fooptr->recsize; No difference, so I guess it gets the value to multiply the increment from the lvalue. Is there a way to do what I want without using a temporary variable (such as assigning to a char * and then doing the increment) or converting the pointer to an integral type, doing the addition and converting back? Thanks, Joe Herman dzoey@terminus.umd.edu -- "Everything is wonderful until you know something about it."