Can a C compiler rearrange stack variables?

前端 未结 11 2277
孤街浪徒
孤街浪徒 2020-12-09 11:07

I have worked on projects for embedded systems in the past where we have rearranged the order of declaration of stack variables to decrease the size of the resulting executa

11条回答
  •  执念已碎
    2020-12-09 11:29

    The stack need not even exist (in fact, the C99 standard does not have a single occurence of the word "stack"). So yes, the compiler is free to do whatever it wants as long as that preserves the semantics of variables with automatic storage duration.

    As for an example: I encountered many times a situation where I could not display a local variable in the debugger because it was stored in a register.

提交回复
热议问题