Following these two links: Should C declarations match definition including keywords and qualifiers such as "static", "inline", etc
and
https://www.greenend.org.uk/rjk/tech/inline.html
They say the following is the way to use inline functions in C:
a.c
#include <stdio.h>
inline int add(int a , int b){
return a+b;
}
int main(){
printf("%d\n", add(1,2));
return 0;
}
b.c
int add(int a , int b);
inline int add(int a , int b){
return a+b;
}
Then compile with: gcc a.c b.c.
Now here is my confusion:
Why does adding a declaration of int add(int a , int b); to b.c cause a symbol generation? I thought only function definitions create symbols in a translation unit not their declarations. Why is this backwards? Is inline a special case?
It's really wired that I have to have an external symbol to work with inline functions.
Why can't C compile a.c on it's own! (I know gnu89 and C++ do, wondering why c99 was coded like this to begin with).