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

Max number of variable declarations

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



Joined: 16 Feb 2004
Posts: 26

View user's profile Send private message

Max number of variable declarations
PostPosted: Tue Oct 10, 2006 5:39 am     Reply with quote

Hi
Is it possible to have too many variable declerations in a procedure?

I have 10 int and 2 int32 in a certain procedure. When I have this in the program it disrupts my printf routines!
If I reduce the ints in this procedure then all is fine?
Any ideas?
Thanks
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 10, 2006 8:13 am     Reply with quote

Post the simplest code that compiles and showes the error.
Ttelmah
Guest







PostPosted: Tue Oct 10, 2006 10:27 am     Reply with quote

What compiler version?.
What chip?.
There are several 'traps for the unwary', to be aware of. First, is that if (for instance), a subroutine, returns the address of a variable it uses internally, this variable _must_ be declared as static, or it is not guaranteed to exist in any external routine.
Generally, the compiler will warn you if there is not enough RAM to hold all the variables, but in order to ue the RAM efficiently, it is 're-used', aned the above illustrates how problems can therefore arise.
As a similar example, if the printf, calls two routines, that directly return values through the 'scratch' area, the values from the second routine can overwrite those from the first. So, in certain circumstances, a call like:

printf("%4ld %4ld %4ld",routine(),routine(),routine());

Can result in the earlier values becoming corrupted by the latter calls. If instead you use:

a=routine();
b=routine();
c=routine();
printf("%4ld %4ld %4ld",a,b,c);

This corruption does not occur, since the values each have their own storage.
If you look at the .lst file, it will show the memory usage.

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