[Bug c/126702] undefined reference to inline function

antonio at gnu dot org via Gcc-bugs <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126702

--- Comment #8 from Antonio Diaz Diaz <antonio at gnu dot org> ---
> note that in C++ inline behaves closer to what you'd like

Thanks. Since long ago I use 'static inline', but the problem at hand is not
about writing new code but about compiling old packages. I found the trouble
while trying to build an old version of clzip, which gcc <= 4.7.4 built, but
gcc >= 10.5.0 failed to build.

Thank you all for your answers. I begin to think that all of you are right and
what is wrong is the C99 standard in that it allows the compiler to choose what
definition to use, producing different behavior depending on the optimization
level if the definitions are different. C++, OTOH, behaves consistently.

For example, consider a program formed by these two files:

f.c
inline int f( void ) { return 1; }
extern int f( void );

main.c
inline int f( void ) { return 0; }
int main( void ) { return f(); }

When compiled with gcc, main returns 1 when compiled with -O0, but it returns 0
when compiled with -O2. OTOH, when compiled with g++, main always returns 0
when compiled with any -O level.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.