Reputation: 1369
Say I have a function with the inline keyword in a compilation unit.
If I have
// math.h
inline int sum(int x, int y);
and
// math.c
inline int sum(int x, int y)
{
return x + y;
}
and
// main.c
#include "math.h"
int main(int argc, char **argv)
{
return sum(argc,argc);
}
And building with
gcc -O3 -c math.c -o math.o
gcc -O3 -c main.c -o main.o
gcc math.o main.o
Will an optimizing compiler inline sum
? Can gcc or clang inline functions from other compilation units?
Upvotes: 1
Views: 223
Reputation: 21906
GCC can (and often will) inline functions from different TUs when you compile with LTO enabled. For this you need to add -flto
to CFLAGS
/CXXFLAGS
and LDFLAGS
.
Upvotes: 2