Thank you Charles and Seymore. I thought that the problem had something to do with adding to pointers but I could not find any doc about it in the manuals. I am still not sure that I understand how to fix it but I will try based on your info.
-----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Charles Mills Sent: Thursday, February 08, 2018 11:33 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: Silly C problem adding hex 6C Yes, pointer arithmetic is scaled by the item size. Works kind of like a subscript. If foo is an int* then foo+1 points to the next integer. (IOW foo+4 if you think in assembler terms.) The basic strategy is to cast it to a char* and then back. If you would like, here are two template functions that will do the trick you want to accomplish. // Pointer absolute arithmetic // This one matches if no explicit typename template<typename T> static inline T *PointerAdd(const T *ptr, const int increment) { return (T *)( reinterpret_cast<const char *>(ptr)+increment ); } // This one matches if explicit typename template<typename T> static inline T *PointerAdd(const void *ptr, const int increment) { return (T *)( reinterpret_cast<const char *>(ptr)+increment ); } How to use? Here is an example of adding an absolute length to a struct pointer: apfePtr = PointerAdd(apfePtr, apfePtr->apfelen); Charles -----Original Message----- From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf Of Seymour J Metz Sent: Thursday, February 8, 2018 8:12 AM To: IBM-MAIN@LISTSERV.UA.EDU Subject: Re: Silly C problem adding hex 6C Isn't pointer arithmetic in C scaled by the item size? ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN ________________________________ This e-mail, including any attachments, may be confidential, privileged or otherwise legally protected. It is intended only for the addressee. If you received this e-mail in error or from someone who was not authorized to send it to you, do not disseminate, copy or otherwise use this e-mail or its attachments. Please notify the sender immediately by reply e-mail and delete the e-mail from your system. ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN