c语言内联嵌套的限制:这有硬限制吗?

c语言内联嵌套的限制:这有硬限制吗?,c,linux,gcc,inline,compiler-optimization,C,Linux,Gcc,Inline,Compiler Optimization,我正在用C编写一个项目。编译时,我遇到以下错误: warning: inlining failed in call to 'xyz()' --param max-inline-insns-single limit reached 我的编译器将警告报告为错误,我不想绕过它 那么,这是不是因为内联函数嵌套太多?我能做些什么来让它工作(除了不内联声明函数之外) 谢谢 正如前面所指出的: 最大内联insns单个: 几个参数控制gcc中使用的树内联线。这个数字在树内联会考虑内联的单个函数中设置指令的最

我正在用C编写一个项目。编译时,我遇到以下错误:

warning: inlining failed in call to 'xyz()'  --param max-inline-insns-single limit reached
我的编译器将警告报告为错误,我不想绕过它

那么,这是不是因为内联函数嵌套太多?我能做些什么来让它工作(除了不内联声明函数之外)

谢谢

正如前面所指出的:

最大内联insns单个:

几个参数控制gcc中使用的树内联线。这个数字在树内联会考虑内联的单个函数中设置指令的最大数量(在GCC的内部表示中计数)。这只影响内联声明的函数和类声明中实现的方法(C++)。默认值为500

如果您仍然希望将警告视为错误(不是不合理的要求),只需使用:

--param max-inline-insns-single=1000
(或更大的值)将其从默认值提升。

如前所述:

最大内联insns单个:

几个参数控制gcc中使用的树内联线。这个数字在树内联会考虑内联的单个函数中设置指令的最大数量(在GCC的内部表示中计数)。这只影响内联声明的函数和类声明中实现的方法(C++)。默认值为500

如果您仍然希望将警告视为错误(不是不合理的要求),只需使用:

--param max-inline-insns-single=1000

(或一些更大的值)将其从默认值提升。

gcc/g++提供了调整
内联线的选项

-finline-limit=n
By default, GCC limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (i.e., marked with the inline keyword or defined within the class definition in c++). n is the size of functions that can be inlined in number of pseudo instructions (not counting parameter handling). The default value of n is 600. Increasing this value can result in more inlined code at the cost of compilation time and memory consumption. Decreasing usually makes the compilation faster and less code will be inlined (which presumably means slower programs). This option is particularly useful for programs that use inlining heavily such as those based on recursive templates with C++.
Inlining is actually controlled by a number of parameters, which may be specified individually by using --param name=value. The -finline-limit=n option sets some of these parameters as follows:

max-inline-insns-single
is set to n/2. 
max-inline-insns-auto
is set to n/2. 
min-inline-insns
is set to 130 or n/4, whichever is smaller. 
max-inline-insns-rtl
is set to n.
因此,您可以增加
n
的值。尽管手动进行衬里不是一个好主意(编译器在这方面非常擅长)


阅读更多或
mangcc

gcc/g++提供选项来调整
内联线

-finline-limit=n
By default, GCC limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (i.e., marked with the inline keyword or defined within the class definition in c++). n is the size of functions that can be inlined in number of pseudo instructions (not counting parameter handling). The default value of n is 600. Increasing this value can result in more inlined code at the cost of compilation time and memory consumption. Decreasing usually makes the compilation faster and less code will be inlined (which presumably means slower programs). This option is particularly useful for programs that use inlining heavily such as those based on recursive templates with C++.
Inlining is actually controlled by a number of parameters, which may be specified individually by using --param name=value. The -finline-limit=n option sets some of these parameters as follows:

max-inline-insns-single
is set to n/2. 
max-inline-insns-auto
is set to n/2. 
min-inline-insns
is set to 130 or n/4, whichever is smaller. 
max-inline-insns-rtl
is set to n.
因此,您可以增加
n
的值。尽管手动进行衬里不是一个好主意(编译器在这方面非常擅长)


阅读更多或
mangcc

您是否使用了
#pragma
uu属性uu
?请注意,这与嵌套无关,它与将插入的指令数有关。您是否使用了
#pragma
u属性u
?请注意,这与嵌套无关,这与插入指令的数量有关。奇怪的是,C(与C++不同)在指定时是否需要内联?在C++中,编译器总是有特权的。@ PATATOSWATER,实际上没有,内联 C是编译器的建议:C117.7.4/5“使函数为内联函数,建议对函数的调用尽可能快”。因此,编译器不能内联的内联函数,它们是否会被视为正常的非内联函数,而不报告错误?我希望我能把这个参数改为1000,我正在处理一个大型项目的一个小模块。谢谢你@tarun27sh,是的,如果它不能内联,它将是一个正常的函数,假设您允许编译器编译:-)在我看来,您有两个选项。按原样编译(警告即错误)并通过增加参数删除警告,或者不将警告视为错误。如果愿意,您可以将其中任何一种效果定位到单个模块。或者,如果您不能执行这两项操作,它也不会内联,因此请删除
inline
关键字。@tarun27sh
-Werror
是一把双刃剑。我建议向项目经理/管理员提及
inline
的可选“建议”语义,并关闭该警告。或者是对所讨论的特定函数的回顾。只是好奇,C(与C++不同)在指定时是否需要内联?在C++中,编译器总是有特权的。@ PATATOSWATER,实际上没有,内联 C是编译器的建议:C117.7.4/5“使函数为内联函数,建议对函数的调用尽可能快”。因此,编译器不能内联的内联函数,它们是否会被视为正常的非内联函数,而不报告错误?我希望我能把这个参数改为1000,我正在处理一个大型项目的一个小模块。谢谢你@tarun27sh,是的,如果它不能内联,它将是一个正常的函数,假设您允许编译器编译:-)在我看来,您有两个选项。按原样编译(警告即错误)并通过增加参数删除警告,或者不将警告视为错误。如果愿意,您可以将其中任何一种效果定位到单个模块。或者,如果您不能执行这两项操作,它也不会内联,因此请删除
inline
关键字。@tarun27sh
-Werror
是一把双刃剑。我建议向项目经理/管理员提及
inline
的可选“建议”语义,并关闭该警告。或者对所讨论的特定功能进行审查。