问题描述
4月11日下午6:06 * pm,Eric Sosman< esos ... @ ieee-dot-org.invalidwrote:
* * *我对那些认为所有全球
变量都是事实上邪恶的狂热者毫无耐心。 *当有人这样做时,我很高兴
提供
* * * * #include< stdio.h>
* * * * int main(无效){
* * * * * * puts(Hello,world!);
* * * * * *返回0;
* * * *}
...并邀请他消除全局变量,即
全局变量,其名称甚至没有提到!
prog output.txt
但我想当你最终查看数据时,全局变量
它会让它变得丑陋。
追逐由于全局变量引起的问题(过去更糟糕的是,使用
Fortran公共区块,通常被视为公共工会)
很容易厌倦''他们。
他们并非都是邪恶的。只有他们中的大多数。
我讨厌的那些是完全不必要的,从懒惰中产生了
思考。
#define常量是维护程序员的祸害。他们通常无法在调试器中读取
。
-
Ian Collins。
#define在一些C程序员中获得了一个奇怪的声誉,
和一个我不太懂的。主要的反对意见似乎是,在调试器中,它们无法读取。
我刚在gdb中尝试过这个。我没有使用gdb很多,但是我知道/如何使用它,所以我写了以下程序:
#include < stdio.h>
#define X 42
int main(无效)
{
printf("%d \ n",X);
返回0;
}
并将程序加载到gdb中。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++
(gdb)运行
启动程序:[...] ./ foo
断点1,main()at foo.c:7
7 printf("%d \ n",X);
(gdb)print X
无符号X在当前的背景下。
+++++++++++++++++++++++++++++++++++++++++ br />
哦,亲爱的我。但是等等!
++++++++++++++++++++++++++++++++++++++++++++++ ++
(gdb)list
2
3 #define X 42
4
5 int main(无效)
6 {
7 printf("%d \ n",X);
8返回0;
9}
10
(gdb)
++++++++++ +++++++++++++++++++++++++++++++++++++++++++在原始源代码中查看
值。所以我真的不认为这是一个严重的反对意见。
我认为这取决于你与谁交谈。 (这也取决于你认为是谁b / b $ g $ b。)
-
Richard Heathfield< http:/ /www.cpax.org.uk>
电子邮件:-http:// www。 + rjh @
谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>
Usenet是一个奇怪的放置" - dmr 1999年7月29日
On Apr 11, 6:06*pm, Eric Sosman <esos...@ieee-dot-org.invalidwrote:
* * *I have no patience with zealots who argue that all global
variables are ipso facto evil. *When someone does so, I delight
in offering
* * * * #include <stdio.h>
* * * * int main(void) {
* * * * * * puts("Hello, world!");
* * * * * * return 0;
* * * * }
... and inviting him to eliminate the global variable, that is,
the global variable whose name isn''t even mentioned!
prog output.txt
But I guess when you look at the data eventually, the global variable
will rear its ugly head.
After chasing down problems due to globals (it used to be worse, with
Fortran common blocks which were often treated like public unions)
it''s easy to get sick of ''em.
They are not all evil. Only most of them.
The ones I hate are the totally unnecessary ones, spawned from lazy
thinking.
#define constants are the scourge of the maintenance programmer. They
are often impossible to read in a debugger.
--
Ian Collins.
#define has gained a strangely poor reputation amongst some C programmers,
and one that I don''t really understand. The principal objection seems to
be that, in a debugger, they are "impossible to read".
I just tried this in gdb. I don''t use gdb a great deal, but I know /how/ to
use it, so I wrote the following program:
#include <stdio.h>
#define X 42
int main(void)
{
printf("%d\n", X);
return 0;
}
and loaded the program into gdb.
+++++++++++++++++++++++++++++++++++++
(gdb) run
Starting program: [...]./foo
Breakpoint 1, main () at foo.c:7
7 printf("%d\n", X);
(gdb) print X
No symbol "X" in current context.
+++++++++++++++++++++++++++++++++++++
Oh deary deary me. But wait!
+++++++++++++++++++++++++++++++++++++
(gdb) list
2
3 #define X 42
4
5 int main(void)
6 {
7 printf("%d\n", X);
8 return 0;
9 }
10
(gdb)
+++++++++++++++++++++++++++++++++++++
Also, of course, we can simply look in the original source code to see the
value. So I really don''t see this as being a serious objection.
It depends who you talk to, I think. (It also depends on whom you consider
to be gurus.)
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
这篇关于Re:为什么人们说'extern'容易出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!