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



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to