Stack space and declarations
Václav Haisman
V.Haisman@sh.cvut.cz
Fri Dec 16 10:16:00 GMT 2005
Andreas Pfeil wrote:
> Hi,
>
> which architecture are you talking about? On PowerPC, if none of the
> variables are marked volatile, then probably no stack space will be
> allocated for the variables. This depends on the ABI of the processor,
> I'd believe.
I understand that the whole thing can be architecture dependent.
The code is just for illustration. Let's say that the variables are all
used in //some code and that the compiler will have to store them onto
the stack. On x86 it would be because of lack of registers. What I want
to know is what is the general approach that the compiler takes. In
other words, does this theoretically lessen stack space pressure?
>
> Cheers,
> Andreas
>
> Václav Haisman wrote:
>
>> Hi,
>> first some C code:
>>
>> void foo (int x)
>> {
>> int y = 0;
>> if (x) {
>> int z = 0;
>> // some more code
>> }
>> else {
>> int w = 0;
>> // some more code
>> }
>> }
>>
>> Now, how much stack space is getting allocated in the function? Is it
>> (assuming 32bit architecture) 2*4=8 bytes (y + (z or w)) or is it 3*4=12
>> (each variable gets its own slot)?
>>
>>
>> Vaclav Haisman
Vaclav Haisman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 546 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20051216/b8bfa913/attachment-0001.sig>
More information about the Gcc-help
mailing list