This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: (extern int vs. int) and (extern function vs. function) (was: gcc-in-cxx update)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]