SmartVessel

Foucs on C++

博客园 首页 新随笔 联系 订阅 管理

2011年4月13日 #

摘要: 糊涂了很久,看了别人的解释,似懂非懂的。今天终于看了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 阅读全文
posted @ 2011-04-13 13:49 SmartVessel 阅读(317) 评论(0) 推荐(0) 编辑

摘要: 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 ( 阅读全文
posted @ 2011-04-13 11:09 SmartVessel 阅读(530) 评论(0) 推荐(0) 编辑

摘要: 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 阅读全文
posted @ 2011-04-13 10:26 SmartVessel 阅读(231) 评论(0) 推荐(0) 编辑

摘要: 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 阅读全文
posted @ 2011-04-13 10:19 SmartVessel 阅读(419) 评论(0) 推荐(0) 编辑