开发者

operating system loops variable stack question

cout << "blah blah blah";
for (int i=0; i < n; i++)
{
 cout << '#' << endl;;
}
cout << "blah blah blah";

is the integer i on the stack frame? if the integer can only be used in the loop, how does the operating system keep track of what variables can only be used in the 开发者_开发知识库loop and not in the entire function?


The operating system doesn't have anything to do with it - it's the compiler's job.

Any decent system will keep i in a cpu register


The variable i is almost certainly placed in a register in this case.

It is the compiler, not the operating system, which enforces the rule that the variable is accessible only within the loop. (It is a compile time rule, not a run time rule.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜