使用gcc内联C代码中的所有功能 [英] Inline all the functions in C code with gcc
问题描述
我有很多C程序没有递归。
我想获得没有用户定义函数但主函数的程序。
GCC可以执行内嵌,但这是在IR级别,所以我可以'code $ c $>
消息来源:
int calc( int a,int b)
{
a = a + b-2;
返回a;
}
int main()
{
int x = 4,y = 7;
x = calc(x,y);
返回0;
TARGET:
int main()
{
int x = 4,y = 7;
int calc_A = x,calc_B = y;
calc_A = calc_A + calc_B-2;
x = calc_A;
返回0;
提供了一个函数属性由gcc调用,名为 用法: > int add(int arg1,int arg2)__ attribute __((always_inline)); //原型 但是,您必须手动将此属性附加到每个函数。 p> 我仍然假设您的所有函数遵循需要内联的规则。例如没有转到,递归等。 I have many C programs without recursion.
I want to get the program without user-defined function but the main function.
GCC can do the inline but that's in IR level so I can't get C code . SOURCE: TARGET:
There is a function attribute provided by gcc, called Usage: However, you would have to manually attach this attribute to every function. I am still assuming that all your functions follow rules which are necessary to be inlined. e.g. no goto, recursion, etc. 这篇关于使用gcc内联C代码中的所有功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! always_inline
$ b
int add(int arg1,int arg2){
return arg1 + arg2;
}
int calc(int a , int b)
{
a=a+b-2;
return a ;
}
int main()
{
int x=4,y=7;
x=calc(x,y);
return 0 ;
}
int main()
{
int x=4,y=7;
int calc_A=x,calc_B=y;
calc_A=calc_A+calc_B-2;
x=calc_A;
return 0 ;
}
always_inline
.int add(int arg1, int arg2)__attribute__((always_inline)); // prototype
int add(int arg1, int arg2){
return arg1+arg2;
}