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

Memory allocation in array declaration?

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








Memory allocation in array declaration?
PostPosted: Thu Aug 25, 2005 5:17 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 25, 2005 6:28 am     Reply with quote

Sounds like you are to blame. You are probably over writing your buffers. Example code is needed if you want help.
Ttelmah
Guest







PostPosted: Thu Aug 25, 2005 6:31 am     Reply with quote

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