CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

pointer math

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

pointer math
PostPosted: Wed May 16, 2007 10:20 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Re: pointer math
PostPosted: Wed May 16, 2007 6:49 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group