Re: stack allocation and gcc

Ihar 'Philips' Filipau
2004-03-10T15:06:30Z

Richard B. Johnson wrote:
> The caller expects that the space for the second set of local
> variables in the second program unit is not allocated until the
> program unit is entered.
>
> I don't know why he would expect this behavior. Certainly

It was my first thought actually - when I have started typeing in
e-mail.

When I have reached half e-mail - I have understood that this is
simple performance consideration - stack space is allocated once.

I have tryed to convert my e-mail to another issue - but seems I did
it not good enough :-)

But then I realized that my thinking was wrong - I'm using variables
in different never overlapping contextes. But space allocated for
everyone. "if (..) { int i; }; if (...) { int i; }" will result not in
sizeof(int) stack space allocated - but in sizeof(int)*2.

It seems that gcc check size required by all top level contextes in
function - it checks for "if { int a[16] } else { int a[16] }" - space
allocated correctly.
But 'if () { int a[16]; }; if () { int a[16] };' seems to break
something, and sum of the sizes for both if()'s spaces finishes
allocated on stack. And this was the case with macro in my module.

I doubt I can write competent report/query to gcc mail list -
probably it is worth to ask there.