Shriramana Sharma wrote: > In man:gcc under -fkeep-inline-functions I first came across the usage > of "extern inline". For normal functions, extern declares that the > function exists elsewhere. But this does not seem to work for inline > functions: > > lib.cpp: Note that way in which "inline" is handled differs between C and C++. > --------------------------------------- > inline int foo ( void ) { return 2 ; } > --------------------------------------- > > main.cpp: > --------------------------------------- > # include <cstdio> > extern inline int foo ( void ) ; > int main ( void ) { > printf ( "%d\n", foo () ) ; > } > --------------------------------------- > > $ g++ -c main.cpp lib.cpp > main.cpp:3: warning: inline function -Fʽint foo()ʼ used but never defined-A > $ g++ -o main main.o lib.o > main.o: In function `main': > main.cpp:(.text+0x12): undefined reference to `foo()' > collect2: ld returned 1 exit status > $ > > nm on lib.o returned absolutely nothing! Apparently code for an inline > function is not produced if it is never called. True for C++, not for C. > If it is called, and it > is not labeled static inline, then it is both inlined and compiled > separately. Strange, but ok. > > So I tried adding a dummy function to lib.cpp calling foo() just to make > it get compiled. Then compiling main.cpp gave the same warning as above, > but linking and execution went on ok. > > But I discovered that I don't need to have the inline keyword in the > declaration of foo() in main.cpp. In fact, removing the inline keyword > allows compilation without warning. > > So what is the *unique* use of extern inline? I mean, where we cannot do > without it? "extern inline" is meaningless. You can only inline functions which occur in the current translation unit. -- Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx> - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html