注册 登录
编程论坛 C++教室

想发个帖子,问问关于全局变量的看法

醉生梦死 发布于 2007-08-25 19:47, 697 次点击
想问问常编程的人,对于全局变量一般在什么情况用,或者说什么样的变量定义为全局变量最合适,大家讨论一下,我吸收点,谢谢
2 回复
#2
aipb20072007-08-26 02:27
习惯,经验

写多了就有自己的见解了。
#3
HJin2007-08-26 07:41
We normally restrain us from using any global variables, since we want to make each module as independent from other modules as possible.

However, when you are studying programming you can use globals.

Globals have two drawbacks:

1. Any function can modify it;
2. In multi-threading programming, you don't know which thread modifies the value so that you have to use mutex, lock/unlock, etc. This complicates the situation.



1