C ++的“内联” - GCC和Clang / LLVM的提示有多强? [英] C++'s "inline" - how strong a hint is it for GCC and Clang/LLVM?

查看:171
本文介绍了C ++的“内联” - GCC和Clang / LLVM的提示有多强?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,关键字inline有两个目的。首先,它允许定义出现在多个翻译单元中。第二,这是编译器的一个提示,一个函数应该被内联在编译的代码。

In C++, the keyword "inline" serves two purposes. First, it allows a definition to appear in multiple translation units. Second, it's a hint to the compiler that a function should be inlined in the compiled code.

我的问题:在GCC和Clang / LLVM生成的代码, inline是否具有任何功能是否内联?如果是,在什么情况下?还是完全忽略了提示?注意,这不是一个语言问题,它是一个特定于编译器的问题。

My question: in code generated by GCC and Clang/LLVM, does the keyword "inline" have any bearing on whether a function is inlined? If yes, in what situations? Or is the hint completely ignored? Note this is a not a language question, it is a compiler-specific question.

推荐答案

[注意:不是C ++ / GCC guru]您想阅读在线内容

[Caveat: not a C++/GCC guru] You'll want to read up on inline here.

此外,适用于GCC / C99。


使用内联
函数说明符提出的
建议的有效范围(C99
6.7 .4)。

The extent to which suggestions made by using the inline function specifier are effective (C99 6.7.4).


  • 如果-fno-inline选项是
    ,或者-O0是用过的。否则,由于很多原因,GCC
    可能仍然无法嵌入
    函数;
    -Winline选项可用于确定函数是否未
    内联,以及为什么不。

所以看来除非你的编译器设置(如 -fno-inline -O0 ),编译器接受提示。我不能评论Clang / LLVM(或GCC真的)。'

So it appears that unless your compiler settings (like -fno-inline or -O0) are used, the compiler takes the hint. I can't comment on Clang/LLVM (or GCC really).'

我建议使用 -Winline if这不是一个代码高尔夫问题,你需要知道发生了什么。

I recommend using -Winline if this isn't a code-golf question and you need to know what's going on.

这篇关于C ++的“内联” - GCC和Clang / LLVM的提示有多强?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆