在堆栈变量顺序(GCC) [英] Order of variables in the stack (GCC)
问题描述
当在GCC编译C code,有没有什么办法来保证堆栈变量会出现在我宣布的顺序栈(或相反的顺序,不要紧,我)?我知道这是可能通过结构,但我宁可不使用它们。
When compiling C code in GCC, is there any way to guarantee that the stack variables will appear in the stack in the order i declare them (or in reversed order, doesn't matter to me)? I know this is possible via structs but I would rather not use them.
推荐答案
的唯一方法是一个结构,其中包括在你喜欢的顺序排列的所有变量。
The only way would be a struct which includes all variables in the order you like.
有关局部变量的编译器可以自由地重新安排它适合她的任何命令/再利用的变量。有些变量可能没有一个内存位置在所有的,他们只能住在寄存器,其他人将被完全优化掉。
For local variables the compiler is free to reorder/reuse variables at any order it suits her. Some variables may not have a memory location at all, they live only in registers, others will be optimized away completely.
这篇关于在堆栈变量顺序(GCC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!