GNU bug report logs -
#12116
merge from gnulib for extern-inline
Previous Next
Reported by: Paul Eggert <eggert <at> cs.ucla.edu>
Date: Wed, 1 Aug 2012 22:27:01 UTC
Severity: normal
Tags: patch
Done: Paul Eggert <paul.eggert <at> verizon.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
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
inlined.
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
macros:
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:
#ifndef CHARSET_INLINE
# define CHARSET_INLINE INLINE
#endif
CHARSET_INLINE void
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:
#define CHARSET_INLINE EXTERN_INLINE
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.
This bug report was last modified 12 years and 298 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.