为什么在"静态"关键字在C和C ++如此多的含义? [英] Why does the "static" keyword have so many meanings in C and C++?

查看:184
本文介绍了为什么在"静态"关键字在C和C ++如此多的含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我们所知,关键字静态拥有的多重含义在C. C99 的补充法律上写的可能性

As we know, the keyword static has multiple meanings in C. C99 added the possibility of legally writing

void foo (int arr[static 50])
{
    // ...
}

这增加了混乱,而C ++有静态成员变量和函数。

which adds to the confusion, and C++ has static member variables and functions.

这也不会这么麻烦,如果所有的用途可能以某种方式进行连接,但我觉得很难找到链接,有些案件。特别是为什么静态关键字应该用于修改能见度(联动),或者是在地球上它有一个数组的最低元素的量做。

This would not be so troublesome if all the uses could be connected in some way, but I find it hard to find that link for some of the cases. Particularly why the static keyword should be used to modify visibility (linkage), or what on earth it's got to do with an array's minimum amount of elements.

那么,有没有为静态关键字的滥用有历史原因的,或者是有连接所有它的用途吗?引擎盖下的秘密链接

So is there a historical reason for the abuse of the static keyword, or is there a secret link under the hood that connects all of its uses?

推荐答案

添加新的关键字的语言打破向后兼容性。因此,静态被用在它的使用有可能会意味着什么( INT改编[静态50] VS INT ARR [汽车50] INT改编[EXTERN 50] )和基于它在previous使用不能语法出现在那个位置版本。

Adding new keywords to a language breaks backwards compatibility. So static gets used where its use might possibly mean something ( int arr[static 50] vs int arr[auto 50] or int arr[extern 50] ) and cannot syntactically appear in that location based its use in previous versions.

虽然在这种情况下,在该位置将不会突破previous code添加 not_less_than 上下文相关的关键字,这将增加另一个关键词(这么简单的文本编辑这是关键字知道,但不知道语法不知道它是否是一个关键字),并打破关键字不上下文敏感的简化用C的。

Though in that case adding a not_less_than context sensitive keyword in that position would not break previous code, it would add another keyword (so simple text editors which are keyword aware but not syntax aware would not know whether or not it is a keyword), and break the 'keywords are not context sensitive' simplification made in C.

这篇关于为什么在"静态"关键字在C和C ++如此多的含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆