[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fwd: Re: [avr-gcc-list] Re: Stack use - possible bug]
From: |
David Brown |
Subject: |
[Fwd: Re: [avr-gcc-list] Re: Stack use - possible bug] |
Date: |
Wed, 09 Jun 2010 21:49:41 +0200 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
(Posted on behalf of Jan Waclawek)
The compiler /does/ know when variables are used or not. But the usual
way to allocate frame space is to allocate the maximum needed space on
function entry, and free it on function exit.
That's OK as long as it works.
Consider this simple example:
volatile uint8_t b;
int main (void) {
while(1) {
{
uint8_t a1[200];
b = a1[b];
}
{
uint8_t a2[200];
b = a2[b];
}
}
}
a1 and a2 have a non-overlapping scope, so the maximum needed space is
200 bytes.
The compiler compiles this simple example OK allocating 200 bytes;
however, in more convoluted cases but where variables have still
non-overlapping scopes, it sometimes allocates 400 bytes.
I believe the problem with inline functions is only a variation on this
problem.
Jan Waclawek
PS. It would help to trace a bit the effect if there would be a simple
tool to list local/auto variables of a function togehter with their
allocation on the stack, but I know of no such. It might be interesting
to see the effect of using different versions of the compiler, too.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fwd: Re: [avr-gcc-list] Re: Stack use - possible bug],
David Brown <=