• <small id='LmLBK'></small><noframes id='LmLBK'>

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

      1. <legend id='LmLBK'><style id='LmLBK'><dir id='LmLBK'><q id='LmLBK'></q></dir></style></legend>
        <tfoot id='LmLBK'></tfoot>

        内联函数和静态内联函数的区别

        Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
        <legend id='6wNi7'><style id='6wNi7'><dir id='6wNi7'><q id='6wNi7'></q></dir></style></legend>
          <tbody id='6wNi7'></tbody>

        • <bdo id='6wNi7'></bdo><ul id='6wNi7'></ul>

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

                  <small id='6wNi7'></small><noframes id='6wNi7'>

                1. 本文介绍了内联函数和静态内联函数的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  谁能告诉我内联函数和静态内联函数有什么区别?

                  Can anybody tell me what the difference is between an inline function and static inline function?

                  在哪些情况下我应该更喜欢静态内联而不是内联?

                  In which cases should I prefer static inline over inline?

                  我问这个问题是因为我有一个内联函数,我在链接过程中遇到了编译问题(重定位错误:...符号已被丢弃部分丢弃...).我使它成为一个正常的功能并且它起作用了.现在我的一些前辈告诉我尝试使用静态内联.以下是我的功能:

                  I am asking this question because I have an inline function for which I am facing compilation issues during linking (relocation error:... symbol has been discarded with discarded section ...). I made it a normal function and it worked. Now some of my seniors told me try with static inline. Below is my function:

                  inline void wizSendNotifier (const char* nn_name, bpDU* arg=0, int aspect = -1)
                  {
                     wizuiNotifier* notifier = ::wizNtrKit.getNotifier (nn_name);
                     notifier->notify (arg, aspect);
                  }
                  

                  而这不是在课堂内.这是在一个头文件中!

                  and this not inside a class. This is inside a header file!

                  我想对静态函数的调用应该只在定义它的特定 TU 中完成.

                  I guess the call to a static function should be done only in the particular TU where it is defined.

                  由于我的函数在头文件中,如果我将其设为静态,那么在我包含该头文件的地方是否会在该翻译单元中使用静态函数?

                  Since my function is in a header file and if i make it static, will it be the case that where ever I include that header file the static function can used used in that translation unit?

                  推荐答案

                  非静态inline 函数声明在使用它的每个翻译单元(源文件)中引用相同的函数.

                  The non-static inline function declaration refers to the same function in every translation unit (source file) that uses it.

                  单一定义规则要求函数定义的主体在包含它的每个 TU 中都是相同的,并且有一个较长的相同"定义.如果源文件都使用相同的标头,并且该函数不使用任何具有内部链接的全局名称(包括 static 函数)或任何在不同的 TU.

                  The One Definition Rule requires that the body of the function definition is identical in every TU that contains it, with a longish definition of "identical". This is usually satisfied provided that the source files all use the same header, and provided that the function doesn't use any global names with internal linkage (including static functions) or any macros that are defined differently in different TUs.

                  我不记得以前遇到过那个特定的链接器错误,但至少有可能是这些限制之一造成的.您有责任满足这些要求:未定义的行为,如果您不满足,则无需诊断.

                  I don't remember encountering that particular linker error before, but it's at least possible that one of these restrictions is responsible. It's your responsibility to satisfy the requirements: undefined behavior with no diagnostic required if you don't.

                  static inline 函数声明指的是每个翻译单元中的不同函数,恰好具有相同的名称.它可以使用在不同 TU 中不同的 static 全局名称或宏,在这种情况下,该函数在不同 TU 中的行为可能不同,即使其在头文件中的定义看起来相同".

                  The static inline function declaration refers to a different function in each translation unit, that just so happens to have the same name. It can use static global names or macros that are different in different TUs, in which case the function might behave differently in the different TUs, even though its definition in the header file "looks the same".

                  由于这种差异,如果函数包含任何static 局部变量,那么它的行为会根据它是否为static 而有所不同.如果它是 static,那么每个 TU 都有自己的函数版本,因此有自己的 static 局部变量副本.如果它是 inline only,那么所有 TU 使用的 static 局部变量只有一个副本.

                  Because of this difference, if the function contains any static local variables then it behaves differently according to whether it is static or not. If it is static then each TU has its own version of the function and hence its own copy of the static local variables. If it's inline only, then there is only one copy of the static local variables used by all TUs.

                  这篇关于内联函数和静态内联函数的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  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 作为模板参数时出错)
                  Validate an argument is ARRAY type in c/c++ pre processing macro on compile time(在编译时验证 c/c++ 预处理宏中的参数是否为 ARRAY 类型)
                  <i id='mwOvx'><tr id='mwOvx'><dt id='mwOvx'><q id='mwOvx'><span id='mwOvx'><b id='mwOvx'><form id='mwOvx'><ins id='mwOvx'></ins><ul id='mwOvx'></ul><sub id='mwOvx'></sub></form><legend id='mwOvx'></legend><bdo id='mwOvx'><pre id='mwOvx'><center id='mwOvx'></center></pre></bdo></b><th id='mwOvx'></th></span></q></dt></tr></i><div id='mwOvx'><tfoot id='mwOvx'></tfoot><dl id='mwOvx'><fieldset id='mwOvx'></fieldset></dl></div>

                        <bdo id='mwOvx'></bdo><ul id='mwOvx'></ul>
                      • <legend id='mwOvx'><style id='mwOvx'><dir id='mwOvx'><q id='mwOvx'></q></dir></style></legend>
                          <tfoot id='mwOvx'></tfoot>

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

                              <tbody id='mwOvx'></tbody>