Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Mar 2009 14:21:00 -0500
From:      David Schultz <das@FreeBSD.ORG>
To:        Luigi Rizzo <rizzo@iet.unipi.it>
Cc:        arch@FreeBSD.ORG
Subject:   Re: C99 inlines
Message-ID:  <20090307192100.GA36158@zim.MIT.EDU>
In-Reply-To: <20090307112449.GB45088@onelab2.iet.unipi.it>
References:  <20090307103138.GA34456@zim.MIT.EDU> <20090307112449.GB45088@onelab2.iet.unipi.it>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, Mar 07, 2009, Luigi Rizzo wrote:
> On Sat, Mar 07, 2009 at 05:31:38AM -0500, David Schultz wrote:
> > I'd like the gcc in our tree to use the C99 semantics instead of GNU
> > semantics for inline functions in C99 and GNU99 mode. The following
> > patch implements this behavior.  It is based on a snapshot of the gcc
> > 4.3 branch from March 2007, prior to the GPLv3 switch.
> > 
> >     http://www.freebsd.org/~das/c99inline.diff
> ...
> > What do people think about this?
> 
> would you be able to provide a short summary of how the C99 and
> GNU99 semantics differ, so that people will have a easier time
> figuring out how to handle the change ?
> 
> Especially, is there anything that a developer should worry about,
> or except from some corner cases the switch will (and should) be
> completely transparent to the average developer without a specific
> interest in compilers ?
> 
> I know what I am asking is probably in the diff you supplied,
> but it's a bit difficult to follow there

Good point; it isn't clear at all from the diffs. Basically it all
has to do with the interpretation of `inline' versus `extern inline'.
Historical gcc semantics are incompatible with C99, but this was
fixed in gcc 4.3. This patch essentially backports that patch from
a development snapshot of gcc 4.3 prior to the GPLv3 switch.

This page summarizes the differences pretty well, but ignore the
last section:

     http://www.greenend.org.uk/rjk/2003/03/inline.html

The most important point for developers is that the one kind of
inline where gcc and C99 agree is `static inline', so if you use
that, you won't have to worry. Otherwise, the semantics you get
depend on many things:

- gcc prior to 4.1.3:
  You always get GNU inline rules.

- gcc 4.1.3 to 4.2.1 (the one in the tree):
  In -std=gnu89 mode, you get GNU inline rules.
  In -std=gnu99 or -std=c99 mode, you get a warning that GNU inline
  rules aren't implemented.

- gcc 4.3+ or gcc with this patch:
  In -std=gnu89 mode, you get GNU inline rules.
  In -std=gnu99 or -std=c99 mode, you get C99 rules.

You can use __gnu89_inline (defined in sys/cdefs.h) or
-fgnu-inline to force the GNU rules regardless, but you can't get
the C99 rules with an unpatched pre-4.3 compiler.  In gcc 4.2+,
the macros __GNUC_{GNU,STDC}_INLINE__ tell you what you're
getting.

With this patch, you basically get the semantics you asked for
instead of a warning that they're not implemented. If you weren't
getting warnings with gcc 4.2 before, then nothing changes.


Another minor consequence of this patch is that it enables a few
new warnings and errors involving non-static inlines. For
instance, if you have an extern inline function that references a
static variable, such that the function might refer to a
*different* version of the variable depending on whether it's
inlined or not, gcc will now tell you you're trying to do
something bogus.  It will also complain if you declare a function
inline but never define it.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090307192100.GA36158>