强制代码内联 [英] forcing code inline

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

问题描述

是否有强制代码内联而不是使

代码为宏?我们在大约十几个地方使用宏来重复约100行代码重复

。我们宁愿把这个

代码内联,但内联似乎可能会将这段代码变成一个函数。


我了解MS __forceinline命令。但是,我们使用

这个代码的三个编译器,VC ++ 2003,Open Watcom 1.5和

gcc 2.95(在FreeBSD盒子上)。


谢谢,

Lynn McGuire

解决方案



Lynn McGuire写道:< blockquote class =post_quotes>是否有强制代码内联而不是使代码成为宏?




Nope。没有标准的方法。你可以提出内联建议

但就是这样。


为什么不相信编译器做正确的事情呢?你正在使用

好​​的编译器......加强一些优化,大多数小的

函数将内联*,当它最适合计算机*时。除非

是否有其他深刻的论据,包括几个冗余的

统计数据,我相信编译器在工作上比我更好。


Lynn McGuire写道:

无论如何强制代码内联,而不是使代码成为一个宏?


不是与平台无关的方式。

我们有大约100行代码复制
使用宏在十几个地方。我们宁愿把这个
代码内联,但是内联似乎可能会使这段代码成为一个函数。


为什么这是件坏事?如果它是100行,那么通过使其内联的任何边际加速

很可能只是一小部分时间

执行代码。事实上,很可能通过

使其内联,你实际上因为缓存而导致执行速度减慢

未命中。

我知道关于MS __forceinline命令。但是,我们使用
三个编译器代码,VC ++ 2003,Open Watcom 1.5和
gcc 2.95(在FreeBSD盒子上)。




gcc也有自己的,非标准的方式来完成它。我不会使用Watcom,但我也认为它也是如此。


祝你好运,


Tom


>>我们有大约100行代码重复

在大约十几个地方使用宏。我们宁愿把这个
代码内联,但内联似乎可能会使这段代码成为一个函数。



为什么这是一件坏事?如果它是100行,那么通过使其内联的任何边际加速将很可能是执行代码所花费的时间的一小部分。事实上,很有可能通过内联,你实际上因为缓存未命中而导致执行速度变慢。




我想要代码重复的另一个原因。我不关心

这段代码的速度。

我知道MS __forceinline命令。但是,我们使用
三个编译器代码,VC ++ 2003,Open Watcom 1.5和
gcc 2.95(在FreeBSD盒子上)。



gcc有自己的代码,非标准的完成方式。我没有使用Watcom,但我也认为它也是如此。




OW无法做到这一点(其他比使用宏)。


谢谢,

Lynn McGuire


Is there anyway to force code to be inline other than making that
code a macro ? We have about 100 lines of code that is duplicated
using a macro in about a dozen places. We would rather make this
code inline but inline seems that it would probably make this code
into a function.

I do know about the MS __forceinline command. However, we use
three compilers for this code, VC++ 2003, Open Watcom 1.5 and
gcc 2.95 (on a FreeBSD box).

Thanks,
Lynn McGuire

解决方案


Lynn McGuire wrote:

Is there anyway to force code to be inline other than making that
code a macro ?



Nope. There is no standard way. You can make the inline suggestion
but that is it.

Why not just trust the compiler to do the right thing? You''re using
good compilers...crank up some optimizations and most of your small
functions will inline *when it is best for the computer*. Unless there
is some profound argument to do otherwise, including several redundant
stats, I trust the compiler to be better at its job than I am.


Lynn McGuire wrote:

Is there anyway to force code to be inline other than making that
code a macro ?
Not in a platform-independent way.
We have about 100 lines of code that is duplicated
using a macro in about a dozen places. We would rather make this
code inline but inline seems that it would probably make this code
into a function.
Why is that a bad thing? If it''s 100 lines, then any marginal speed-up
by making it inline will most likely be some tiny fraction of the time
it takes to execute the code. In fact, it is quite possible that by
making it inline, you actually slow down execution because of cache
misses.
I do know about the MS __forceinline command. However, we use
three compilers for this code, VC++ 2003, Open Watcom 1.5 and
gcc 2.95 (on a FreeBSD box).



gcc has its own, nonstandard way of accomplishing that as well. I
don''t use Watcom, but I assume the same is true of it too.

Best regards,

Tom


>> We have about 100 lines of code that is duplicated

using a macro in about a dozen places. We would rather make this
code inline but inline seems that it would probably make this code
into a function.



Why is that a bad thing? If it''s 100 lines, then any marginal speed-up
by making it inline will most likely be some tiny fraction of the time
it takes to execute the code. In fact, it is quite possible that by
making it inline, you actually slow down execution because of cache
misses.



I want the code duplicated for another reason. I dont care about
speed of this code.

I do know about the MS __forceinline command. However, we use
three compilers for this code, VC++ 2003, Open Watcom 1.5 and
gcc 2.95 (on a FreeBSD box).



gcc has its own, nonstandard way of accomplishing that as well. I
don''t use Watcom, but I assume the same is true of it too.



OW does not have a way of doing this (other than using a macro).

Thanks,
Lynn McGuire


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

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