0

I've read here:

and it stated:

A function defined with inline on its own. Stand-alone object code is always emitted. You can only write one definition like this in your entire program. If you want to use it from other translation units to the one where it is defined, you put a declaration in a header file; but it would not be inlined in those translation units.

however, in my minimal reproducible example:

test.c

inline                                                                                                                                                                         
int foo(void)                                                                                                                                                                  
{                                                                                                                                                                              
  return 0;                                                                                                                                                                    
}                                                                                                                                                                              
                                                                                                                                                                               
int main(void)                                                                                                                                                                 
{                                                                                                                                                                              
  foo();                                                                                                                                                                       
}  

receives

cc -std=c99 -Wall -Wextra -Wshadow -Wpedantic test.c -o test                                                                                                                   
Undefined symbols for architecture x86_64:                                                                                                                                     
  "_foo", referenced from:                                                                                                                                                     
      _main in test-febb67.o                                                                                                                                                   
ld: symbol(s) not found for architecture x86_64                                                                                                                                
clang: error: linker command failed with exit code 1 (use -v to see invocation)                                                                                                
make: *** [Makefile:4: test] Error 1 

so it seems that code is not being properly emitted. The same problem is also present in gcc. What is going on here? Specifically, I'd like to know, what are the differences here:

inline foo(void) { /* definition */ }
foo(void);
foo(void) { /* definition */ }
inline foo(void);

and my case:

inline foo(void) { /* definition */ }
user129393192
  • 797
  • 1
  • 8

0 Answers0