Will a new Stack Frame be created on entering a block of statements?

Possible Duplicate:
In C, do braces act as a stack frame?

int main()
{
   int i=10;

   {
       int i=100;
       printf("%d", i);
   }
}

Will the internal "{" and "}" create a new stack frame?


This is totally implementation dependent, but for implementations out there, the answer is no. The two i variables will typically be implemented by two separate variables in the same stack frame, although in this particular case, the first i might be omitted altogether.

Creating a stack frame (on i386) is only needed when you call a subroutine (even if it were only for the return address). This doesn't happen in your case.


Only if the compiler is feeling an itch. There's certainly no language requirement involved. to be more specific, I can't think of any reason that any compiler would feel an urge to push a frame here except to optimize storage for a very large number of locals. The compiler is perfectly capable of managing the names without a runtime frame.


Perhaps. Perhaps not. The lanaguage does not require it, so the compiler is free to do whatever it wishes.

链接地址: http://www.djcxy.com/p/84316.html

上一篇: 如何在C中取消声明(删除)变量?

下一篇: 在输入语句块时是否会创建一个新的Stack Frame?