gpt4 book ai didi

c++ - C+ +'s "inline"- 对 GCC 和 Clang/LLVM 的提示有多强?

转载 作者:IT老高 更新时间:2023-10-28 22:36:55 29 4
gpt4 key购买 nike

在 C++ 中,关键字“inline”有两个用途。首先,它允许定义出现在多个翻译单元中。其次,它是对编译器的一个提示,一个函数应该在编译后的代码中内联。

我的问题:在 GCC 和 Clang/LLVM 生成的代码中,关键字“inline”是否与函数是否内联有关系?如果是,在什么情况下?还是完全忽略了提示?请注意,这不是语言问题,而是特定于编译器的问题。

最佳答案

[警告:不是 C++/GCC 专家] 你需要阅读 inline here .

Also, this, for GCC/C99.

The extent to whichsuggestions made by using the inlinefunction specifier are effective (C996.7.4).

  • GCC will not inline any functions if the -fno-inline option isused or if -O0 is used. Otherwise, GCCmay still be unable to inline afunction for many reasons; the-Winline option may be used to determine if a function has not beeninlined and why not.

因此,除非使用您的编译器设置(如 -fno-inline-O0),否则编译器会接受提示。我无法评论 Clang/LLVM(或真正的 GCC)。'

如果这不是代码高尔夫问题并且您需要知道发生了什么,我建议使用 -Winline

关于c++ - C+ +'s "inline"- 对 GCC 和 Clang/LLVM 的提示有多强?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5223690/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com