|
|
View previous topic :: View next topic |
Author |
Message |
stma
Joined: 16 Feb 2004 Posts: 26
|
Max number of variable declarations |
Posted: Tue Oct 10, 2006 5:39 am |
|
|
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
|
|
Posted: Tue Oct 10, 2006 8:13 am |
|
|
Post the simplest code that compiles and showes the error. |
|
|
Ttelmah Guest
|
|
Posted: Tue Oct 10, 2006 10:27 am |
|
|
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 |
|
|
|
|
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
|