From: Shriramana Sharma <samjnaa@gmail.com>
To: Linux C Programming List <linux-c-programming@vger.kernel.org>
Subject: What is the use of extern inline?
Date: Tue, 29 May 2007 09:19:34 +0530 [thread overview]
Message-ID: <465BA2CE.9060609@gmail.com> (raw)
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
next reply other threads:[~2007-05-29 3:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-29 3:49 Shriramana Sharma [this message]
2007-06-04 7:01 ` What is the use of extern inline? Glynn Clements
2007-06-11 4:48 ` Shriramana Sharma
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=465BA2CE.9060609@gmail.com \
--to=samjnaa@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).