If I have a pointer to an array of a 4 byte struct and declare a pointer to the first struct and keep incrementing it, how should I deal with the pointer going further than the last struct?
Maybe if( ++pointer == &struct[number of structs] ) pointer--; ?
Right now it is just a ++pointer, so it is dangerous.
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
Re: pointer math
Posted: Wed May 16, 2007 6:49 pm
future wrote:
If I have a pointer to an array of a 4 byte struct and declare a pointer to the first struct and keep incrementing it, how should I deal with the pointer going further than the last struct?
Maybe if( ++pointer == &struct[number of structs] ) pointer--; ?
Right now it is just a ++pointer, so it is dangerous.
For us to make a useful suggestion, you have too post the whole loop that reads the array. _________________ Read the label, before opening a can of worms.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum