内联函数 [英] inline function

查看:74
本文介绍了内联函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++标准是否需要生成所有

时间的内联函数?


例如,


#include< iostream>

使用命名空间std;


inline int foo()

{

返回10;

}


int main()

{

cout< ;< " FOO()=" << foo()<<结束;

}


foo()应该始终在最终的可执行文件中生成吗?


JG

Does C++ standard require an inline function be generated all the
time ?

For example,

#include <iostream>
using namespace std;

inline int foo()
{
return 10;
}

int main()
{
cout << "foo()=" << foo() << endl;
}

Should foo() be generated in the final executable all the time ?

JG

推荐答案

7月31日上午8:51,jg< jgu ... @ gmail.comwrote:
On Jul 31, 8:51 am, jg <jgu...@gmail.comwrote:

C ++标准是否需要生成所有

时间的内联函数?
Does C++ standard require an inline function be generated all the
time ?



inline只是编译器的提示或请求,并且不承诺

任何东西......


Tony

inline is just a hint or request of the compiler, and doesn''t promise
anything...

Tony


7月31日凌晨4:51,jg< jgu ... @ gmail.comwrote:
On Jul 31, 4:51 am, jg <jgu...@gmail.comwrote:

C ++标准是否需要生成所有

时间的内联函数?
Does C++ standard require an inline function be generated all the
time ?



正确的术语是内联,而不是生成。


鉴于此,答案是标准不需要内联

函数一直都要内联。


-N

The correct term is "inlined", not "generated".

Given that, the answer is that the standard doesnot require an inline
function to be inlined all the time.

-N


7月30日晚上8:47,Neelesh Bodas< neelesh .bo ... @ gmail.comwrote:
On Jul 30, 8:47 pm, Neelesh Bodas <neelesh.bo...@gmail.comwrote:

7月31日凌晨4:51,jg< jgu ... @ gmail.comwrote:C ++标准吗要求内联函数生成所有
On Jul 31, 4:51 am, jg <jgu...@gmail.comwrote:Does C++ standard require an inline function be generated all the

时间?
time ?



正确的术语是内联,而不是生成。


鉴于此,答案是标准不要求内联

函数一直内联。


-N


The correct term is "inlined", not "generated".

Given that, the answer is that the standard doesnot require an inline
function to be inlined all the time.

-N



号码我的意思是生成。内联函数是否内联

不是我的问题。我的问题是编译器是否会生成

该内联函数的代码,无论函数

是否内联。


对于我的例子,我试过g ++。没有优化,它确实会生成

foo();与-O,它没有。使用Sun Studio 11,即使没有优化也不会生成

foo()。


JG


it确实产生了

No. I mean "generated". Whether an inline function is inlined or not
is not my question. My question is whether a compiler will generate
the code for that inline function no matter whether the function
is inlined or not.

For my example, I tried g++. Without optimization, it does generate
foo(); with -O, it does not. With Sun Studio 11, it does not generate
foo() even without optimization.

JG

it does generate that


这篇关于内联函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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