C99 inlines

David Schultz das at FreeBSD.ORG
Sat Mar 7 11:16:50 PST 2009

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:


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

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.

More information about the freebsd-arch mailing list