Can a C compiler rearrange stack variables?

前端 未结 11 2287
孤街浪徒
孤街浪徒 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:09

    Not only can the compiler reorder the stack layout of the local variables, it can assign them to registers, assign them to live sometimes in registers and sometimes on the stack, it can assign two locals to the same slot in memory (if their live ranges do not overlap) and it can even completely eliminate variables.

提交回复
热议问题