调用precede函数的定义不能被内联

调用precede函数的定义不能被内联

本文介绍了调用precede函数的定义不能被内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助包含以下内容:

当一个函数同时为inline和静态的,如果对所有来电
  功能集成到呼叫者,而该函数的地址是
  从来没有使用过,那么该函数自身的汇编code是永远不会
  引用。在这种情况下,GCC实际上不输出汇编code
  对于功能,除非你指定选项
  -fkeep内联函数。有些电话不能整合由于各种原因(特别是,调用precede函数的定义
  不能集成
,然后也不能在递归调用
  定义)。

这听起来总是可笑的我 - 为什么一个现代化的编译器是哑巴?快速测试后,它似乎不真实的。

That always sounded absurd to me -- why would a modern compiler be that dumb? After a quick test it does seem untrue.

测试code:

static inline int foo();

int bar() {
    return foo();
}

int foo() {
    return 42;
}

在Linux上使用GCC-4.9.2结果对于 code栏(),但没有为富()。你可以看到,富()已集成:

The result with gcc-4.9.2 on Linux contains code for bar() but none for foo(). You can see that foo() has been integrated:

bar:
.LFB0:
    .cfi_startproc
    movl    $42, %eax
    ret
    .cfi_endproc

如果我编译为C ++的结果是一样的,只是名字粉碎。

If I compile as C++ the result is the same, except for name mangling.

相反,文档,尽管富()通话栏()之后被定义富()已完全集成到巴()

Contrary to the documentation, despite foo() being defined after the call in bar(), foo() has been completely integrated into bar().

不要误解我的文档或者是不正确的?也许这是正确的一些更复杂的情况?

Do I misunderstand the documentation or is it incorrect? Perhaps it's correct for some more complicated case?

我不知道是否有正在使用的关键字来分清整合和内联,但我怀疑集成的技术区别在线,它仅仅指的是内联函数(因此标题)。

I don't know if there's a technical distinction between "integrate" and "inline" but I suspect "integrate" is being used to distinguish from keyword inline and it just refers to function inlining (hence the title).

此问题被标记为C和C ++,因为GCC文档的这一部分涉及到C语言家族,我希望答案是两种语言相同。

This question is tagged as C and C++ because this portion of the gcc documentation pertains to the "C language family" and I expect the answer to be the same for the two languages.

推荐答案

使用gcc来编译,并尽快在同一时间优化一个功能,因为他们解析,解析在下单前。 IIRC,它只是在他们推出的4.X时间框架 -funit-AT-A-时间选项,它推迟了优化后看了整个编译单元然后他们等待某些版本中默认启用它。

Gcc used to compile and optimize one function at a time, as soon as they were parsed, before parsing the next one. IIRC, it is only in the 4.X time frame that they introduced the -funit-at-a-time option which postponed the optimization to after having read the whole compilation unit and then they waited some releases to enable it by default.

呼叫后定义内联函数的可能性可能已经被引入作为一部分 -funit-AT-A-时间工作,并内嵌的文件(该再提一下通话preceding的定义可以追溯到至少2.95)还没有更新呢。

The possibility of inlining function defined after the call has probably be introduced as part of the -funit-at-a-time work, and the documentation of inline (the mention about calls preceding the definition dates back at least to 2.95) has not updated then.

这篇关于调用precede函数的定义不能被内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 22:14