<bdo id='Xszeq'></bdo><ul id='Xszeq'></ul>

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

      <legend id='Xszeq'><style id='Xszeq'><dir id='Xszeq'><q id='Xszeq'></q></dir></style></legend>
    1. <tfoot id='Xszeq'></tfoot>
    2. <i id='Xszeq'><tr id='Xszeq'><dt id='Xszeq'><q id='Xszeq'><span id='Xszeq'><b id='Xszeq'><form id='Xszeq'><ins id='Xszeq'></ins><ul id='Xszeq'></ul><sub id='Xszeq'></sub></form><legend id='Xszeq'></legend><bdo id='Xszeq'><pre id='Xszeq'><center id='Xszeq'></center></pre></bdo></b><th id='Xszeq'></th></span></q></dt></tr></i><div id='Xszeq'><tfoot id='Xszeq'></tfoot><dl id='Xszeq'><fieldset id='Xszeq'></fieldset></dl></div>
      1. 存储类、存储持续时间、文件范围、生存期、链接混淆

        storage class, storage duration, file scope, lifetime, linkage confusion(存储类、存储持续时间、文件范围、生存期、链接混淆)
              <tbody id='C7bnd'></tbody>
          1. <legend id='C7bnd'><style id='C7bnd'><dir id='C7bnd'><q id='C7bnd'></q></dir></style></legend><tfoot id='C7bnd'></tfoot>
              <bdo id='C7bnd'></bdo><ul id='C7bnd'></ul>

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

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

                  本文介绍了存储类、存储持续时间、文件范围、生存期、链接混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当谈到一个C++/C变量时,标准ISO文档提到了storage classstorage durationfile scopelifetimelinkage.

                  When talked about a C++/C variable, the standard ISO document mentions storage class, storage duration, file scope, lifetime, and linkage.

                  我想了解基本线索以及它们之间的关系.但是读了ISO文档后,我找不到这些概念的清晰逻辑图.

                  I want to understand the basic clues and how they are related to each other. But after reading the ISO documents, I cannot find a clear logic map for these concepts.

                  你能帮忙澄清一下吗?我希望我能用这些概念来分析我的编程问题.

                  Could you help clarify it? I hope I can use there concepts to analyze my programming problem.

                  ISO 文档 部分:

                  • C99 6.7.1 存储类说明符
                  • C99 6.11.2 标识符的链接
                  • C++2003 7.1.1 存储类说明符
                  • C++2003 7.5 链接规范

                  推荐答案

                  存储类说明符是声明语法的decl-specifier-seq的一部分.它们控制由声明引入的名称的两个独立属性:它们的存储持续时间和它们的链接.存储类说明符:

                  Storage class specifiers are a part of the decl-specifier-seq of a declaration syntax. They control two independent properties of the names introduced by the declaration: their storage duration and their linkage. Storage class specifiers:

                  • auto - 自动存储持续时间(直到 C++11)
                  • register - 自动存储时间.还提示编译器将变量放在处理器的寄存器中(已弃用)
                  • static - 静态或线程存储持续时间和内部链接
                  • extern - 静态或线程存储持续时间和外部链接
                  • thread_local - 线程存储持续时间(C++11 起)
                  • auto - automatic storage duration (until C++11)
                  • register - automatic storage duration. Also hints to the compiler to place the variable in the processor's register (deprecated)
                  • static - static or thread storage duration and internal linkage
                  • extern - static or thread storage duration and external linkage
                  • thread_local - thread storage duration (since C++11)

                  存储持续时间:

                  • 自动 存储时间.该变量在封闭代码块的开头分配,并在结束时释放.所有非全局变量都有这个存储持续时间,除了那些声明的 staticexternthread_local.
                  • static 存储时间.该变量在程序开始时分配,在程序结束时释放.该变量仅存在一个实例.所有全局变量都有这个存储持续时间,加上那些用 staticextern 声明的变量.
                  • thread 存储时间.该变量在线程开始时分配,在线程结束时释放.每个线程都有自己的变量实例.只有声明为 thread_local 的变量具有此存储持续时间.thread_local 可以和 staticextern 一起出现来调整联动.(C++11 起)
                  • dynamic 存储时间.使用动态内存分配函数为每个请求分配和释放变量.
                  • automatic storage duration. The variable is allocated at the beginning of the enclosing code block and deallocated on end. All non-global variables have this storage duration, except those declared static, extern or thread_local.
                  • static storage duration. The variable is allocated when the program begins and deallocated when the program ends. Only one instance of the variable exists. All global variables have this storage duration, plus those declared with static or extern.
                  • thread storage duration. The variable is allocated when the thread begins and deallocated when the thread ends. Each thread has its own instance of the variable. Only variables declared thread_local have this storage duration. thread_local can appear together with static or extern to adjust linkage. (since C++11)
                  • dynamic storage duration. The variable is allocated and deallocated per request by using dynamic memory allocation functions.

                  链接.表示对象、引用、函数、类型、模板、命名空间或值的名称可能具有链接.如果名称具有链接,则它引用与另一个作用域中的声明引入的相同名称的相同实体.如果在多个作用域中声明了一个变量、函数或另一个同名实体,但没有足够的链接,则会生成该实体的多个实例.

                  Linkage. A name that denotes object, reference, function, type, template, namespace, or value, may have linkage. If a name has linkage, it refers to the same entity as the same name introduced by a declaration in another scope. If a variable, function, or another entity with the same name is declared in several scopes, but does not have sufficient linkage, then several instances of the entity are generated.

                  识别以下链接:

                  • 无链接.该名称只能从其所在的范围内引用.
                  • 内部链接.可以从当前翻译单元的所有范围引用名称.
                  • 外部链接.可以从其他翻译单元中的范围引用该变量.
                  • No linkage. The name can be referred to only from the scope it is in.
                  • Internal linkage. The name can be referred to from all scopes in the current translation unit.
                  • External linkage. The variable can be referred to from the scopes in the other translation units.

                  参考.

                  这篇关于存储类、存储持续时间、文件范围、生存期、链接混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
                    <bdo id='eLtEZ'></bdo><ul id='eLtEZ'></ul>

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

                    • <legend id='eLtEZ'><style id='eLtEZ'><dir id='eLtEZ'><q id='eLtEZ'></q></dir></style></legend>

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

                              <tbody id='eLtEZ'></tbody>