On Sun, Nov 11, 2018 at 02:58:26PM +0800, Bin.Cheng wrote: > Given below simple code: > > inline int foo (int a) { > return a + 1; > } > int g = 5; > int main(void) { > return foo(g); > }
This is the standard C99 inlining behavior. inline means provide something that can be inlined, but don't generate an external definition. One needs to use the extern keyword in one of the TUs to emit it. See https://gcc.gnu.org/onlinedocs/gcc/Inline.html https://gcc.gnu.org/gcc-4.2/changes.html for more info. You can use -fgnu89-inline, or -std=gnu89, or gnu_inline attribute if you are looking for the GNU inlining semantics rather than C99 one. And of course, in C++ the inlining behavior is yet different (comdat). Jakub