摘要:
糊涂了很久,看了别人的解释,似懂非懂的。今天终于看了stackoverflow里面的解释。自己写了点程序验证了下,终于明白了。局部变量:作用域在一个block里例如if(ture){inti=0;}i就是局部变量,作用域就在大括号里。再看function(){i=0;}局部变量实质在存放在函数的栈中,每一次invoke函数,都会产生变量i,多次调用i之间是不受影响的。#include<iostream>voidf();intmain(){f();f();return0;}voidf(){std::stringlocalA;localA+="ab";std::co 阅读全文
2011年4月13日 #
摘要:
A static global variable is local to the translation unit it is defined in. So, if you define static int a; in two different translation units, this will create two independent variables. If you define a non-static global variable int b; in two translation units, you will experience a linker error ( 阅读全文
摘要:
To simplify just a bit, there are basically three main storage areas you need to be concerned with: Global data -- a single static memory location outside the stack or heap. These are the variables declared not local to any function. (The distinction evident by the C/C++ "static" keyword i 阅读全文
摘要:
Take it with a grain of salt when you read it :) Well, the three things you refer to are automatic, static and dynamic storage duration, which has something to do with how long objects live and when they begin life. You use automatic storage duration for short lived and small data, that is needed on 阅读全文