是否有编译器忽略 C++ 关于默认内联函数的标准?
C++ ISO 标准规定:“在类定义中定义的函数是内联函数。” *
您知道有哪些编译器忽略了此规则吗?
您是否知道有哪些编译器不会将“内联建议”放在那里?
(请不要重复有关内联的理论,我知道这一点 - 我需要一个实际的答案)
C++ ISO standard says: "A function defined within a class definition is an inline function." *
Do you know about any compilers that IGNORE this rule?
Do you know about any compilers that WILL NOT put that 'inline suggestion' there?
(please do not repeat the theory about inlines, I am aware of that - I need a practical answer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
所有编译器都可以忽略他们决定的任何内联建议。 例如,如果他们认为该函数太复杂,则不会内联该函数。 如果您获取了函数的地址,则该函数可能会在某些地方内联,但会在其他地方生成完整的函数以供该地址指向。
当您在类定义中定义函数时,请考虑内联和隐式内联作为对编译器的建议。
All compilers are allowed to ignore any inline suggestions they decide to. If they decide the function is too complex, for example, it won't be inlined. If you ever take the address of the function, the function may be inlined in some places, but a full function generated somewhere else for the address to point to.
Think of
inline
and the implicit inline when you define a function in a class definition as suggestions to the compiler.这不是规则,它只是事实的陈述。 规范只是简单地说明该函数是内联定义的。 这使得编译器也更容易实际内联生成的代码,但标准中没有任何地方要求这样做。
它们是不同的概念。 生成的代码的外观仅取决于编译器,并且标准实际上并没有强加任何要求(当然,它应该按照指定的方式运行)。
It is not a rule, it is simply a statement of fact. The spec is simply stating that the function is defined inline. That makes it easier for the compiler to actually inline the generated code as well, but nowhere does the standard require this.
They're different concepts. What the generated code looks like is up to the compiler alone, and the standard doesn't really impose any requirements (except of course that it should behave as specified).
在海湾合作委员会你可以使用
In gcc you can use
请参阅我对一个非常类似问题的回答:什么时候“内联”无效? (在C中)
总结:inline只需要允许多个定义。 任何调用更改的函数都是纯粹可选的。
See my answer to a very similar question: When is "inline" ineffective? (in C)
Summary: inline is only required to allow multiple definitions. Any function calling changes is purely optional.