Discussion:
_GL_INLINE issue
Tim Rühsen
2018-04-13 09:52:10 UTC
Permalink
You likely know it, but just in case I report it here.

We use 'static _GL_INLINE' for some static functions we want to get
inlined. This works out fine (compiles without warning) at least with
gcc5-, gcc-6, gcc-7 and gcc-8, also with several versions of clang.

On the GCC Compile farm there is gcc70 (NetBSD 5.1 with gcc 4.1.3) which
errors with 'duplicate static'. Removing the 'static' keyword cmpiles
fine there, but doesn't on newer systems (link error, unknow external
reference to those functions).


I'll remove _GL_INLINE from my code since it seems more problematic then
it helps.

That follows the advice from
https://www.gnu.org/software/gnulib/manual/html_node/extern-inline.html:
"C code ordinarily should not use inline. Typically it is better to let
the compiler figure out whether to inline, as compilers are pretty good
about optimization nowadays. In this sense, inline is like register,
another keyword that is typically no longer needed."

With Best Regards, Tim
Bruno Haible
2018-04-13 14:03:45 UTC
Permalink
Hi Tim,
Post by Tim Rühsen
We use 'static _GL_INLINE' for some static functions we want to get
inlined.
This is a wrong use of '_GL_INLINE'.

There are 3 uses of the keyword 'inline' in C:
1) 'static inline'.
2) 'inline' and 'extern inline'.

Portable use of 1) is simple:
- use AC_REQUIRE([AC_C_INLINE])
- use 'static inline' in the code.

Portable use of 2) is more involved: This is what
https://www.gnu.org/software/gnulib/manual/html_node/extern-inline.html
is about.

When you write 'static _GL_INLINE', you are mixing up the cases 1) and 2).
Post by Tim Rühsen
"C code ordinarily should not use inline. Typically it is better to let
the compiler figure out whether to inline, as compilers are pretty good
about optimization nowadays. In this sense, inline is like register,
another keyword that is typically no longer needed."
This advice applies to modern compilers.

By the way, Paul, what is the problem with telling the compiler what to
'static inline'? In other words, what was the motivation of changing
'static inline' to 'static' - other than "it's not needed" - in the
13 patches presented on November 09, 2012 in
https://lists.gnu.org/archive/html/bug-gnulib/2012-11/ and committed on
2012-11-29 ?

Bruno
Tim Rühsen
2018-04-13 14:23:35 UTC
Permalink
Hi Bruno,
Post by Bruno Haible
Hi Tim,
Post by Tim Rühsen
We use 'static _GL_INLINE' for some static functions we want to get
inlined.
This is a wrong use of '_GL_INLINE'.
1) 'static inline'.
2) 'inline' and 'extern inline'.
- use AC_REQUIRE([AC_C_INLINE])
- use 'static inline' in the code.
Portable use of 2) is more involved: This is what
https://www.gnu.org/software/gnulib/manual/html_node/extern-inline.html
is about.
When you write 'static _GL_INLINE', you are mixing up the cases 1) and 2).
Ah ! Thanks for the clarification :-)

We indeed only wanted to use 1)


With Best Regards, Tim
Ben Pfaff
2018-04-13 14:28:45 UTC
Permalink
Post by Bruno Haible
By the way, Paul, what is the problem with telling the compiler what to
'static inline'? In other words, what was the motivation of changing
'static inline' to 'static' - other than "it's not needed" - in the
13 patches presented on November 09, 2012 in
https://lists.gnu.org/archive/html/bug-gnulib/2012-11/ and committed on
2012-11-29 ?
For functions defined in .c files, I like to avoid "static inline"
because "inline" prevents the compiler from warning me when a function
is unused, which I often find to be a useful warning.
Paul Eggert
2018-04-13 19:26:01 UTC
Permalink
Post by Bruno Haible
what was the motivation of changing
'static inline' to 'static' - other than "it's not needed"
Partly so that the relevant modules wouldn't require AC_C_INLINE. As I
vaguely recall, I wanted to work around issues when gcc -fno-inline was
used. This was during the reorganization when we got Gnulib to work
better with extern inline and C11.

Simplicity is good too....
Bruno Haible
2018-04-13 20:33:04 UTC
Permalink
Post by Paul Eggert
Post by Bruno Haible
what was the motivation of changing
'static inline' to 'static' - other than "it's not needed"
Partly so that the relevant modules wouldn't require AC_C_INLINE.
This is a bit backwards: In gnulib, we usually write the C code first,
and then put together the .m4 file and the module description so that
it fits with the C code. Not the other way around.
Post by Paul Eggert
I wanted to work around issues when gcc -fno-inline was used.
This was during the reorganization when we got Gnulib to work
better with extern inline and C11.
OK, so I guess this is not a sufficient reason for eliminating all current
and future uses of 'static inline', from dfa.c to regexec.c.
Post by Paul Eggert
For functions defined in .c files, I like to avoid "static inline"
because "inline" prevents the compiler from warning me when a function
is unused, which I often find to be a useful warning.
Good point.

And debuggability with gdb. Single-stepping through inline functions is
quite confusing. On the other hand, for debugging, I most often compile
with "-O0 -ggdb" anyway, which inhibits the inlining even of 'static inline'
functions.

Bruno

Loading...