Gcc - 2 versions, various handling of built-in functions

I recently ran into a problem in my project. I usually compile it in gcc-4, but after trying to compile in gcc-3, I noticed another call to the built-in functions. To illustrate this, I created a simple example:

main.c:

#include "header.h"
#include <stdio.h>

int main()
{
    printf("f() %i\n", f());
    return 0;
}

file.c:

#include "header.h"
int some_function()
{
    return f();
}

header.h

inline int f()
{
    return 2;
}

When I compile the code in gcc-3.4.6 with:

gcc main.c file.c -std=c99 -O2

( f), , -O2. , -, , , f , , main.c, file.c, . , , f static, , , f .

gcc-4.3.5 :

gcc main.c file.c -std=c99 -O2

, gcc inlined f , f ( gdb, ).

, -O2, undefined int f(). , . , gcc , f , , ( -O2) , .

: , , , ? ? , , gcc-4 , , ?

+3
1

, gcc-4.3 . gcc inline doc (http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Inline.html).

: , gcc ( ), . gcc,   , gcc f() : .

Gcc 4.3 c99.

, :

: , , , ? ? , , gcc-4 , , ?

, gcc .

+5

Source: https://habr.com/ru/post/1751357/


All Articles