[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12116: merge from gnulib for extern-inline

From: Paul Eggert
Subject: bug#12116: merge from gnulib for extern-inline
Date: Thu, 02 Aug 2012 11:02:59 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120714 Thunderbird/14.0

On 08/02/2012 08:07 AM, Eli Zaretskii wrote:
> Can you explain what it does?

The basic idea is to support globally-used inline functions
using the way established by C99 standard.  C99 does it
by putting this into a .h file:

   inline foo (int x) { return bar (x); }

and by also declaring FOO to be extern in one .c file.  In a
non-optimizing implementation FOO's machine code is generated for
that .c file, and all uses invoke that machine code.  In an optimizing
implementation, FOO is expanded inline when that makes sense,
and FOO's machine code can be optimized away if all calls to FOO are

The way it's done in gnulib and Emacs is to use the above scheme
when C99 style extern inline works, and to fall back on 'static inline'
for older compilers, or even to plain 'static' if the compiler is so
ancient that it doesn't even grok 'inline'.  In Emacs we have the

                             e x p a n s i o n   i n :
   macro           C99            older compilers   ancient compilers
   INLINE          inline         static inline     static
   EXTERN_INLINE   extern inline  static inline     static

and the Emacs include file charset.h does this:


   set_charset_attr (struct charset *charset, enum charset_attr_index idx,
                     Lisp_Object val)
     ASET (CHARSET_ATTRIBUTES (charset), idx, val);

so in C99 most users of charset.h see the function as being
'inline void'.  charset.c does this before including charset.h:


so that when it's compiled, the function is 'extern inline void'.
In pre-C99 compilers the function is 'static inline' or (if ancient)
plain 'static'.  Similarly for each .h file that uses inline functions.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]