Re: forcing a variable to be on the stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 06/10/2010 17:20, Andrew Haley wrote:
On 10/06/2010 04:11 PM, Mathieu Lacage wrote:
Is there a way to ask gcc to force a specific variable to be stored on
the stack ?

Take its address.


Taking a variable's address on it's own is not enough. If the compiler can figure out that you are not using the address, or that it can find a different way to get the same effect, then the variable will stay in a register (or be optimised away altogether, if possible).

Of course, there are not many reasons why you would /want/ to force a variable onto the stack unless it was because you want to be able to take its address...

(other than write a bit of inline asm ?)

Nothing wrong with that:

  asm volatile ("" ::"a"&foo);

Andrew.



"volatile" is always the key to forcing the compiler to do things.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux