linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* What is the use of extern inline?
@ 2007-05-29  3:49 Shriramana Sharma
  2007-06-04  7:01 ` Glynn Clements
  0 siblings, 1 reply; 3+ messages in thread
From: Shriramana Sharma @ 2007-05-29  3:49 UTC (permalink / raw)
  To: Linux C Programming List

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:
---------------------------------------
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 ‘int foo()’ used but never defined
$ 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. 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?

Shriramana Sharma.

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-06-11  4:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-05-29  3:49 What is the use of extern inline? Shriramana Sharma
2007-06-04  7:01 ` Glynn Clements
2007-06-11  4:48   ` Shriramana Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).