内联工作如何? [英] How does inlining work?

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

问题描述

虽然我对内联的工作方式有很好的感觉,但如果没有描述内联函数,我无法看到世界内联中的b / b


" ;到位在头文件中,而是在单独的源中定义

文件(使用内联关键字),它被链接到?在这种情况下,inling

是否可以工作?如果确实如此,有人可以解释一下编译器如何处理这个问题?如果没有,是否有文件

某处?


谢谢,

Gus

While I have a very good feel for how inlining works, I fail to see how
in the world inlining can work if the inlined function is not described
"in place" in a header file, but rather defined in a separate source
file (using the inline keyword), which gets linked in? Does inling
work at all in such cases? If it does, can someone kindly explain how
the compilers handle that? If it does not, is that documented
somewhere?

Thanks,
Gus

推荐答案

Generic Usenet Account写道:
Generic Usenet Account wrote:
虽然我对内联工作有很好的感觉,但我没看到
如何如果内联函数没有就地描述,那么在世界内联中可以起作用。在一个头文件中,而是在一个单独的源文件中定义(使用内联关键字),它被链接到了什么?在这种情况下,inling是否工作?如果确实如此,那么有人能够解释编译器如何处理这个问题吗?如果没有,是否记录在哪里?
While I have a very good feel for how inlining works, I fail to see
how in the world inlining can work if the inlined function is not
described "in place" in a header file, but rather defined in a
separate source file (using the inline keyword), which gets linked
in? Does inling work at all in such cases? If it does, can someone
kindly explain how the compilers handle that? If it does not, is
that documented somewhere?




内联函数的定义必须存在并且必须相同

在每个调用它的翻译单元(即源文件)中。如果你在
中调用多个源文件中的内联函数,显然这样做的方法

是将定义放在头文件中并#include每个文件中的头文件/>
源文件,但是如果你想要的话,你可能不会,你可以在每个来源中单独和相同地明确定义函数

文件。


我有时会在源文件而不是标题中放置内联函数

文件如果我不在其他任何地方使用它(例如,一个私人班级成员

功能)。


DW



The definition of an inline function must be present and must be identical
in every translation unit (i.e., source file) in which it is called. If you
call an inline function in multiple source files the obvious way to do this
is to place the definition in a header file and #include the header in each
of the source files, but if you want, which you probably don''t, you can
explicitly define the function separately and identically in each source
file.

I sometimes place an inline function in a source file rather than a header
file if I don''t use it anywhere else (e.g., a private class member
function).

DW


Generic Usenet Account写道:
Generic Usenet Account wrote:
虽然我对内联的工作方式有很好的感觉,但如果没有描述内联函数,我就无法看到世界内联中的
如何工作
;在头文件中,而是在一个单独的源文件(使用内联关键字)中定义,它被链接在?在这种情况下,inling
会起作用吗?如果确实如此,有人可以解释一下编译器如何处理它?如果没有,是否有文件记录?

谢谢,
Gus
While I have a very good feel for how inlining works, I fail to see how
in the world inlining can work if the inlined function is not described
"in place" in a header file, but rather defined in a separate source
file (using the inline keyword), which gets linked in? Does inling
work at all in such cases? If it does, can someone kindly explain how
the compilers handle that? If it does not, is that documented
somewhere?

Thanks,
Gus




否,内联关键字单独是不足以让函数调用

内联。


为了内联函数,编译器还必须具有

函数'的实现。因此,内联函数是在头文件中声明的
。如果编译器在编译对该函数的调用时没有看到内联的

函数的主体,则不会内联函数

调用。


未能内联函数调用不被视为错误;通常

没有迹象表明函数调用没有内联。但

大多数C ++编译器都有设置报告错误,只要

编译器无法内联函数。


Greg



No, the inline keyword alone is not enough to let a function call be
inlined.

In order to inline a function the compiler must also have the
function''s implementation on hand. For this reason inline functions are
declared in header files. If the compiler has not seen the inlined
function''s body when it compiles a call to that function, the function
call will not be inlined.

Failing to inline a function call is not considered an error; generally
there wil be no indication that a function call was not inlined. But
most C++ compilers have a setting to report an error whenever the
compiler was unable to inline a function.

Greg


* Generic Usenet帐户:
* Generic Usenet Account:

虽然我对内联工作有很好的感觉,但是b $ b

呃,你不是。 ;-)


如果没有描述内联功能,我无法看到世界内联中的
如何工作
就地在头文件中,而是在一个单独的源文件(使用内联关键字)中定义,它被链接在?


这是不允许的。


在这种情况下,是否会进行工作?


如果你删除''inline''关键字以获得一致的程序文本,

然后是,它可以工作。这称为整个程序优化,或全局

优化。例如,Microsoft的Visual C ++就是这样做的。


如果确实如此,有人可以解释一下编译器是如何处理的吗?


通常情况下,链接器负责这项工作,因为只有链接器

才有可用的必要信息。如果或当我们将模块放入

语言时,可能在C ++ 0x中,编译器可能会贡献更多。或者

不是,取决于标准化过程的结果。


如果没有,是否记录在某处?

While I have a very good feel for how inlining works,
Uh, you don''t. ;-)

I fail to see how
in the world inlining can work if the inlined function is not described
"in place" in a header file, but rather defined in a separate source
file (using the inline keyword), which gets linked in?
That is not allowed.

Does inling work at all in such cases?
If you remove the ''inline'' keyword so as to get a conforming program text,
then yes, it can work. That''s called "whole program optimization", or "global
optimization". For example, Visual C++ from Microsoft does this.

If it does, can someone kindly explain how the compilers handle that?
Generally it''s the linker that takes care of this job, because only the linker
has the necessary information available. If or when we get modules into the
language, possibly in C++0x, the compiler may be able to contribute more. Or
not, depending on how the standardization process turns out.

If it does not, is that documented somewhere?




如果你的意思是,无论你的无效使用''inline''关键字是否记录为

无效,那么这就是C ++标准。如果你的意思是,整个程序在某处记录了优化,那将是你编译器的文档。


-

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

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的是什么?



If you mean, whether your invalid use of the ''inline'' keyword is documented as
invalid anywhere, then that''s the C++ standard. If you mean, is whole program
optimization documented somewhere, that''ll be your compiler''s documentation.

--
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?


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

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