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 CCS Technical Support

Problem with pointers

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



Joined: 17 Jan 2012
Posts: 17

View user's profile Send private message

Problem with pointers
PostPosted: Thu Mar 21, 2013 2:11 am     Reply with quote

Sometimes i have problems with big arrays and pointers:
for example when i use it this way everything is allright:
float example(float *something_external)
{
int8 i;
float something;
for(i=0;i<10;i++)
{
something+=*something_external;
something_external++;
}
return something;
}
BUT when i use it this way sometimes it makes some problems
float example(float *something_external)
{
int8 i;
float something;
for(i=0;i<10;i++)
{
something+=*(something_external+i);
}
return something;
}

Any ideas?
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 2:20 am     Reply with quote

Incorrect syntax.....
You want.
Code:

something+=(*something_external)+i;


You are saying to add 'i' to the pointer, _then_ take the contents of this. Effectively treating it as an array, so

Code:

something+=something_external[i];


Best Wishes
monsun



Joined: 17 Jan 2012
Posts: 17

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 2:44 am     Reply with quote

Ive thought that something_external[i] is equal to *(something_external+i) using pointers??
Ttelmah



Joined: 11 Mar 2010
Posts: 19512

View user's profile Send private message

PostPosted: Thu Mar 21, 2013 3:15 am     Reply with quote

OK. So you do want to use it as an array?.

Question then is compiler version and chip???.

If you want to use it as an array, then 'yes' this is right, _but only if you are on a modern compiler_. Historically the older compilers did not increment pointers correctly, treating their size as '1', whatever they pointed to.
There were also problems on particular chips when you crossed page boundaries.

Best Wishes
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