The C programming Language -1.10 External Variables and Scope

来源:互联网 发布:天谕捏脸数据玉虚男 编辑:程序博客网 时间:2024/05/21 10:24

By the way, there is a tendency to make everything in sight an extern variable because it appears to simplify communications-argument lists are short and variables are always there when you want them. But external variables are always there even when you don't want them. Relying too heavily on external variables is fraught with peril since it leads to programs whose data connections are not all obvious-variables can be changed in unexpected and even inadvertent ways, and the program is hard to modify. The second version of the longest-line program is inferior to the first, partly for these reasons, and partly because it destroys the generality of two useful functions by writing into them the names of the variables they manipulate.


外部变量要慎用,过渡依赖外部变量会导致一定的风险。而且在改写longest-line program的时候,因为把函数操作的变量写进了函数内部,破坏了函数的通用性。

原创粉丝点击