lua-users home
lua-l archive

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

Ah, sorry to be here again.  You may surely skip this.

Andrew Cagney wrote in

 |> From: Roberto Ierusalimschy <>
 |> Sent: Monday, November 14, 2022 11:45 AM
 |> To: Lua mailing list
 |> Subject: Re: Question on replacing macros with static inline functions
 |>> I noticed that Lua code sometimes uses macros where a static inline \
 |>> function
 |>> would appear to work equally as well.
 |>> [...]
 |>> How interested would the Lua development team be in replacing such \
 |>> macros with
 |>> functions in the future?
 |> Inline functions is not present in C89, and Lua is (still) compatible
 |> with C89.

 |On Mon, 14 Nov 2022 at 11:49, Brent Pappas <> \
 |> I see, that makes sense.
 |> Thanks for the quick reply.
 |I'd expect those macros to be around for some time:
 |- GCC didn't adopt C99 inline semantics until GCC 4.3 and that was
 |only released in 2008
 | ); sticking with macros
 |avoids that compatibility headache

But just to note that gcc did support inline by other means many
years earlier, via __inline__.  Linkage was a bit messy so you
could do "extern __inline__" or "static __inline__" which was
better but would complain about unused functions iirc.  Ie you
could simply have lots of injected static functions without
__inline__ if that would not be supported.  Or you did
a tremendous dance of doing "extern myprefix_function()" and
"XYINLINE myinlineprefix_function()", which you could inject only
upon optimization time or when the implementation compiles, and
use preprocessor macros to define myprefix_function() to
myinlineprefix_function() in the former case only.  And
myprefix_function() would do nothing but assertions etc and then
call myinlineprefix_function().  (You can still call
myprefix_function() via (myprefix_function)(), ie, for taking the
address.)  I think the Linux kernel by that time (~2000) was full
of extern __inline__.

 |- putting the stubs in .c files works well with modern compilers (the
 |link-time optimizer will eliminate the call), older compilers don't
 |support this though and take a hit; sticking to macros avoids this

I personally always felt it was a shame that the ({ .. })
extension of gcc never made it to a standard.  But now that C++ is
about to eliminate the preprocessor (as i heard), that ship has

P.S.: not to mention that once in a while gcc reintroduces bugs
that some inline functions not actually happen, the latest two
examples (i know of) being an "-Os" inlining bug in March 2019

   #  if defined __STDC_VERSION__ && __STDC_VERSION__ +0 >= 199901L
  +     /* xxx gcc 8.3.0 bug: does not truly inline with -Os */
  +#    if su_CC_GCC && defined __OPTIMIZE_SIZE__
  +#     define su_INLINE inline __attribute__((always_inline))
  +#    else
  +#     define su_INLINE inline
  +#    endif

and in June this year, when a windriver guy reported something
with -Og (that i did not even know), so now i have finally dropped
it all and only go for what i did for clang always:

  # elif su_CC_CLANG || su_CC_GCC || su_CC_PCC
  #  if defined __STDC_VERSION__ && __STDC_VERSION__ +0 >= 199901l
  #   if !defined NDEBUG || !defined __OPTIMIZE__
  #    define su_INLINE static inline
  #    define su_SINLINE static inline
  #   else
       /* clang does not like inline with <-O2 */
  #    define su_INLINE inline __attribute__((always_inline))
  #    define su_SINLINE static inline __attribute__((always_inline))
  #   endif
  #  else
  #   if su_CC_VCHECK_GCC(3, 1)
  #    define su_INLINE static __inline __attribute__((always_inline))
  #    define su_SINLINE static __inline __attribute__((always_inline))
  #   else
  #    define su_INLINE static __inline
  #    define su_SINLINE static __inline
  #   endif
  #  endif
  # endif

Actually i have lost track.  But twenty years ago it worked
flawless as stated above.  (But which was _tremendous_ work.)


|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)