<small id='R8cUW'></small><noframes id='R8cUW'>

<tfoot id='R8cUW'></tfoot>
  • <i id='R8cUW'><tr id='R8cUW'><dt id='R8cUW'><q id='R8cUW'><span id='R8cUW'><b id='R8cUW'><form id='R8cUW'><ins id='R8cUW'></ins><ul id='R8cUW'></ul><sub id='R8cUW'></sub></form><legend id='R8cUW'></legend><bdo id='R8cUW'><pre id='R8cUW'><center id='R8cUW'></center></pre></bdo></b><th id='R8cUW'></th></span></q></dt></tr></i><div id='R8cUW'><tfoot id='R8cUW'></tfoot><dl id='R8cUW'><fieldset id='R8cUW'></fieldset></dl></div>
    • <bdo id='R8cUW'></bdo><ul id='R8cUW'></ul>

        <legend id='R8cUW'><style id='R8cUW'><dir id='R8cUW'><q id='R8cUW'></q></dir></style></legend>

        为什么“静态"关键字在 C 和 C++ 中有这么多含义?

        Why does the quot;staticquot; keyword have so many meanings in C and C++?(为什么“静态关键字在 C 和 C++ 中有这么多含义?)
      1. <small id='xm4Cu'></small><noframes id='xm4Cu'>

        <i id='xm4Cu'><tr id='xm4Cu'><dt id='xm4Cu'><q id='xm4Cu'><span id='xm4Cu'><b id='xm4Cu'><form id='xm4Cu'><ins id='xm4Cu'></ins><ul id='xm4Cu'></ul><sub id='xm4Cu'></sub></form><legend id='xm4Cu'></legend><bdo id='xm4Cu'><pre id='xm4Cu'><center id='xm4Cu'></center></pre></bdo></b><th id='xm4Cu'></th></span></q></dt></tr></i><div id='xm4Cu'><tfoot id='xm4Cu'></tfoot><dl id='xm4Cu'><fieldset id='xm4Cu'></fieldset></dl></div>
        <legend id='xm4Cu'><style id='xm4Cu'><dir id='xm4Cu'><q id='xm4Cu'></q></dir></style></legend>

                  <bdo id='xm4Cu'></bdo><ul id='xm4Cu'></ul>
                  <tfoot id='xm4Cu'></tfoot>
                    <tbody id='xm4Cu'></tbody>
                  本文介绍了为什么“静态"关键字在 C 和 C++ 中有这么多含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们知道,关键字 static 具有 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.

                  如果可以以某种方式连接所有用途,这不会那么麻烦,但我发现在某些情况下很难找到该链接.特别是为什么应该使用 static 关键字来修改可见性(链接),或者它到底与数组的最小元素量有什么关系.

                  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.

                  那么,static 关键字的滥用是否有历史原因,或者其背后是否有一个秘密链接可以连接其所有用途?

                  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?

                  推荐答案

                  向语言添加新关键字会破坏向后兼容性.所以 static 在它的使用可能意味着什么的地方被使用( int arr[static 50] vs int arr[auto 50]int arr[extern 50] ) 并且不能根据其在以前版本中的使用在语法上出现在该位置.

                  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.

                  虽然在那种情况下,在那个位置添加一个 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++ 中有这么多含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C++ stl unordered_map implementation, reference validity(C++ stl unordered_map 实现,参考有效性)
                  C++: Is it possible to use a reference as the value in a map?(C++:是否可以使用引用作为映射中的值?)
                  Where ampersand quot;amp;quot; can be put when passing argument by reference?(其中符号“amp;通过引用传递参数时可以放置吗?)
                  Why can a non-const reference parameter be bound to a temporary object?(为什么可以将非常量引用参数绑定到临时对象?)
                  What is a dangling reference?(什么是悬空引用?)
                  C++ reference changes when push_back new element to std::vector(当 push_back 新元素到 std::vector 时,C++ 引用发生变化)
                      <tfoot id='qTyfg'></tfoot>

                        <i id='qTyfg'><tr id='qTyfg'><dt id='qTyfg'><q id='qTyfg'><span id='qTyfg'><b id='qTyfg'><form id='qTyfg'><ins id='qTyfg'></ins><ul id='qTyfg'></ul><sub id='qTyfg'></sub></form><legend id='qTyfg'></legend><bdo id='qTyfg'><pre id='qTyfg'><center id='qTyfg'></center></pre></bdo></b><th id='qTyfg'></th></span></q></dt></tr></i><div id='qTyfg'><tfoot id='qTyfg'></tfoot><dl id='qTyfg'><fieldset id='qTyfg'></fieldset></dl></div>

                        <small id='qTyfg'></small><noframes id='qTyfg'>

                          <tbody id='qTyfg'></tbody>
                            <bdo id='qTyfg'></bdo><ul id='qTyfg'></ul>
                            <legend id='qTyfg'><style id='qTyfg'><dir id='qTyfg'><q id='qTyfg'></q></dir></style></legend>