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 */ } 
2
  • Use static inline and it works. Commented Aug 3, 2023 at 23:33
  • Why's that @Barmar? I'm looking to understand how this works. Commented Aug 3, 2023 at 23:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.