I'm programming a 16f877a.h ... and I have in my program arrays ... at some point take values of other variables and I do not know why? Someone has this happened? please help
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
Posted: Mon Feb 25, 2013 1:14 pm
It is happening, because you are writing beyond the end of an array somewhere.
Arrays are not 'bounds checked' (the hardware does not support this). It is up to _you_ to be careful. So (for instance):
void some_code(void) {
int8 ctr;
for (ctr=1;ctr<=10;ctr++)
chars[ctr]=anumber;
}
//at this point 'something[0]' will probably have been overwritten
The problem here is that in C arrays are zero referenced. So chars has entries from 0 to 9. I then write to entries 1 to 10, and since (generally) variables are stored in memory in the order they are declared, chars[10], overwrites something[0].....
Common causes of problems are:
1) Forgetting arrays are zero referenced.
2) Forgetting strings need space for the terminating null.
3) Just general errors....
Best Wishes
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
Posted: Mon Feb 25, 2013 1:17 pm
Read these threads. See if you are doing anything mentioned in them.
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