我怎么能告诉GCC不要内联函数? [英] How can I tell gcc not to inline a function?

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

问题描述

说我有在源文件中这个小功能。

Say I have this small function in a source file

static void foo() {}

和我建立我的二进制的优化版本但我不想要这个功能,内联(用于优化的目的)。有一个宏,我可以在源$ C ​​$ C至prevent添加内联?

and I build an optimized version of my binary yet I don't want this function inlined (for optimization purposes). is there a macro I can add in a source code to prevent the inlining?

推荐答案

您想要的 GCC 特异性的 noinline始终 属性。

You want the gcc-specific noinline attribute.

此功能属性prevents一个
  从正在考虑功能
  内联。如果函数不
  有副作用,有
  优化内联相比其他
  导致函数调用进行优化
  走,虽然函数调用
  生活。为了使被这样的电话
  优化掉,把
             ASM();

This function attribute prevents a function from being considered for inlining. If the function does not have side-effects, there are optimizations other than inlining that causes function calls to be optimized away, although the function call is live. To keep such calls from being optimized away, put asm ("");

使用这样的:

void __attribute__ ((noinline)) foo() 
{
  ...
}

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

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