1

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:

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 ;
}

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;
    return 0 ;
}
4

1 回答 1

0

gcc 提供了一个函数属性,叫做always_inline.

用法:

int add(int arg1, int arg2)__attribute__((always_inline)); // prototype
int add(int arg1, int arg2){
    return arg1+arg2;
}

但是,您必须手动将此属性附加到每个函数。

我仍然假设您的所有函数都遵循必须内联的规则。例如,没有 goto、递归等。

于 2012-12-20T11:15:16.863 回答