C89, Mixing Variable Declarations and Code

后端 未结 4 881
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 03:26

I\'m very curious to know why exactly C89 compilers will dump on you when you try to mix variable declarations and code, like this for example:

rutski@imac:~         


        
4条回答
  •  执念已碎
    2020-12-17 04:14

    It is similar to requiring functions to be declared before they are used - it allows a simple-minded compiler to operate in one pass, from top to bottom, emitting object code as it goes.

    In this particular case, the compiler can go through the declarations, adding up the stack space required. When it reaches the first statement, it can output the code to adjust the stack, allocating space for the locals, immediately before the start of the function code proper.

提交回复
热议问题