gpt4 book ai didi

c - 我如何告诉 gcc 不要内联函数?

转载 作者:太空狗 更新时间:2023-10-29 16:14:38 24 4
gpt4 key购买 nike

假设我在源文件中有这个小函数

static void foo() {}

并且我构建了我的二进制文件的优化版本,但我不想内联此函数(出于优化目的)。我可以在源代码中添加一个宏来防止内联吗?

最佳答案

您需要特定于 gccnoinline属性。

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() 
{
...
}

关于c - 我如何告诉 gcc 不要内联函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1474030/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com