|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
Memory allocation in array declaration? |
Posted: Thu Aug 25, 2005 5:17 am |
|
|
Hi all,
Ive noticed something about which i wanted ur comments:
when i declare continous memory e.g in the form arrays such as:
char a[9];
char b[8];
char c[5];
the compiler probably treats it internally, as one memory chunk and might store more than 9 character in the array 'a'. On the other hand if i separate the above declaration with some other data type declarations say integers, then the programs works fine !
e.g in my case i was taking input over the Serial port storing in arrayz a,b and c. the data in array 'a' comprised the data of array a and also b's and c's. similarly data in array b comprise b's and c's while array c stored its own data (5 char which i wanted to store).
Any comments, why is it so? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu Aug 25, 2005 6:28 am |
|
|
Sounds like you are to blame. You are probably over writing your buffers. Example code is needed if you want help. |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 25, 2005 6:31 am |
|
|
The answer is that your code is overflowing the areas you are allocating, and adding the extra declarations, gives some leeway, so the overflow does not damage the next stored value.
You need to look vry carefully at how you are storing the values. remember (for instance), that a 9 character string, required _10_ storage locations (there is a null terminator required on a string).
Best Wishes |
|
|
|
|
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
|