This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: (extern int vs. int) and (extern function vs. function) (was: gcc-in-cxx update)
- From: Eus <reply dot to dot eus dot at dot member dot fsf dot org at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: eus at member dot fsf dot org, "Joseph S. Myers" <joseph at codesourcery dot com>, Manuel López-Ibáñez <lopezibanez at gmail dot com>, gcc at gcc dot gnu dot org
- Date: Fri, 01 May 2009 09:04:16 +0700
- Subject: Re: (extern int vs. int) and (extern function vs. function) (was: gcc-in-cxx update)
- References: <m3hc0729jr.fsf@google.com> <Pine.LNX.4.64.0904291120200.23778@digraph.polyomino.org.uk> <6c33472e0904290513j44b3cafdl77b38de0cd2619cd@mail.gmail.com> <Pine.LNX.4.64.0904291321570.25453@digraph.polyomino.org.uk> <6c33472e0904290642j4b243ba3u4ec76b71b0c0e410@mail.gmail.com> <Pine.LNX.4.64.0904291456280.27093@digraph.polyomino.org.uk> <6c33472e0904290819o3b0dafd4s750be6543484dabe@mail.gmail.com> <Pine.LNX.4.64.0904291537250.27093@digraph.polyomino.org.uk> <1241092470.6783.20.camel@eus-laptop> <m3ocuet1e1.fsf@google.com>
- Reply-to: eus at member dot fsf dot org
Hi Ho!
On Thu, 2009-04-30 at 11:57 -0700, Ian Lance Taylor wrote:
> What you are describing is a common and traditional implementation of C,
> but it is not strictly standard conformant. The ISO C standard says
> that "int i;" is always a definition, and "extern int i;" is always a
> declaration. What you decribe is listed as a common extension (at least
> in C90--I didn't bother to check C99).
Thank you for clarifying further in light of the standard.
> Yes. In a function (not variable) declaration, the "extern" is
> optional. This is true in both C and C++.
Thanks for the answer. I had been pondering upon this point for about a
year or so since I hacked the Linux kernel for the very last time. It is
because in some header files, some prototypes use "extern" and some
don't. So, I was curious as to whether they have a different semantic.
> > Also, is there any difference in defining a non-inline function with
> and
> > without "extern" in C? That is, is there any difference between:
> >
> > extern int foo (int *bar)
> > {
> > return *bar + 5;
> > }
> >
> > and
> >
> > int foo (int *bar)
> > {
> > return *bar + 5;
> > }
> >
> > ?
> >
> > I think they are also identical. Am I right? Who knows the one with
> > "extern" can be overridden in another TU defining its own definition
> > without "extern".
>
> These are not identical, but the meaning in C is complex because it
> changes depending on which standard you are using. Look at the docs
> for
> the -fgnu89-inline option and the gnu_inline function attribute.
Ah, I get it.
Yes, I am aware of the different semantic when inline is involved like
what you have specified here:
http://gcc.gnu.org/ml/gcc/2006-11/msg00006.html
> Ian
Thanks for your answers :-)
--
Best regards,
Eus (FSF member #4445)
In this digital era, where computing technology is pervasive, your
freedom depends on the software controlling those computing devices.
Join free software movement today! It is free as in freedom, not as in
free beer!
Join: http://www.fsf.org/jf?referrer=4445