什么内联? [英] What gets inlined?

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

问题描述

我知道这在某种程度上取决于实现,但由于

标准规定了内联说明符,因此必须有一些合理的&b $ b假设。我可以说明当我内联函数时应该发生什么。


假设我有这样的东西(BTW目前被打破了

Qt-4 -rc1):


内联QWidget * vBox(QWidget * parent){

QWidget * box = new QWidget(parent);

QVBoxLayout * boxLayout = new QVBoxLayout(box);

box-> setLayout(boxLayout);

返回框;

}


很明显,在入口点和函数返回

之间会发生很多事情。我的理解是所涉及的所有目标代码

都不会内联,只有

函数调用的编译表示将被内联。这是正确的吗?

-

如果我们的假设是关于任何事情而不是关于某一个或多个特定事物,那么我们的推论就构成了数学。因此,数学可能被定义为我们永远不知道我们所讨论的是什么,以及我们所说的是否属实的主题.- Bertrand Russell

解决方案

* Steven T. Hatton:

我知道这在某种程度上取决于实现,但是从
Standard指定内联说明符,必须有一些合理的假设。我可以说明当我内联函数时会发生什么。

假设我有类似的东西(其中,BTW目前在Qt-4-rc1中被破坏):

直列QWidget的* VBOX(QWidget的*父){
QWidget的*盒=新的QWidget(父);
QVBoxLayout *的BoxLayout =新QVBoxLayout(盒);
箱 - > setLayout(boxLayout);
返回框;
}
很明显,在入口点和从函数返回的
之间会发生很多事情。我的理解是所涉及的所有目标代码都不会被内联,只有
函数调用的编译表示将被内联。这是正确的吗?




编号基本上你不能假设任何东西。这是一个常见问题解答:


< url:http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.3>


如果你想要优化,请告诉你的编译器进行优化。


如果你想控制内联,这是另外一点,使用

特定于编译器的语言扩展。


-

答:因为它弄乱了人们通常阅读文本的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet上最烦人的事情是什么?在电子邮件中?


Steven T. Hatton写道:

我知道这在某种程度上依赖于实现,但由于
标准规定了内联说明符,因此必须有一些合理的假设。我可以说明当我内联函数时会发生什么。




是的。您可以期望能够在多个翻译单元中定义它

而不会出现错误。但是,你不能假设任何内联发生

或不发生。


Rolf Magnus写道:

Steven T. Hatton写道:

我知道这在某种程度上取决于实现,但由于
标准指定了内联说明者,必须有一些合理的假设。我可以说明当我内联
函数时会发生什么。



是的。您可以期望能够在多个翻译单元中定义
而不会出现错误。但是,你不能假设任何内联发生
或不发生。




我的问题与_what_内联有关_if_编译器内联

功能?我怀疑实现之间并没有太大差异,但是我可能错了。

-

如果我们的假设是关于什么,而不是一些或多个特定的东西,然后我们的推论构成数学。因此,数学可能被定义为我们永远不知道我们所讨论的是什么,以及我们所说的是否属实的主题.- Bertrand Russell


I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.

Suppose I have something like this (which, BTW is currently broken in
Qt-4-rc1):

inline QWidget* vBox(QWidget* parent) {
QWidget* box = new QWidget(parent);
QVBoxLayout* boxLayout = new QVBoxLayout(box);
box->setLayout(boxLayout);
return box;
}

Clearly, there will be a lot happening between the entry point, and the
return from the function. My understanding is that all of the object code
involved will not be inlined, and only the compiled representation of the
function calls will be placed inline. Is this correct?
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell

解决方案

* Steven T. Hatton:

I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.

Suppose I have something like this (which, BTW is currently broken in
Qt-4-rc1):

inline QWidget* vBox(QWidget* parent) {
QWidget* box = new QWidget(parent);
QVBoxLayout* boxLayout = new QVBoxLayout(box);
box->setLayout(boxLayout);
return box;
}

Clearly, there will be a lot happening between the entry point, and the
return from the function. My understanding is that all of the object code
involved will not be inlined, and only the compiled representation of the
function calls will be placed inline. Is this correct?



No. Essentially you can''t assume anything. And that''s a FAQ:

<url: http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.3>

If you want optimization, tell your compiler to optimize.

If you want control over inlining, which is something else, use
compiler-specific language extensions.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Steven T. Hatton wrote:

I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a function.



Yes. You can expect to be able to define it in multiple translation units
without getting an error. However, you can''t assume any inlining to happen
or not happen.


Rolf Magnus wrote:

Steven T. Hatton wrote:

I know this is, to some extent, implementation dependent, but since the
Standard specifies an inline specifier, there must be some "reasonable
assumptions" I can make about what should happen when I inline a
function.



Yes. You can expect to be able to define it in multiple translation units
without getting an error. However, you can''t assume any inlining to happen
or not happen.



My question has to do with _what_ gets inlined _if_ the compiler inlines the
function? I suspect that doesn''t vary a lot between implementations, but I
could be wrong.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell


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

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