Let's say I have two files named "AA.c", "BB.c"
/* in AA.c */
inline void AA(void) __attribute__((always_inline));
void AA()
{
/* do something */
}
and then
/* in BB.c */
#include "AA.c"
extern void funcAA(void);
int main(void)
{
funcAA();
return 0;
}
does funcAA( ) also become inline???
no matter the answer is yes or no, could you explain some more about the under the hood??
including a .c file is equivalent of copying and pasting the file contents directly in the file which includes that, exactly like if the function was directly defined in the including file.
You can see what the compiler is going to compile by trying to compile your file with -E
flag (preprocessor output). You'll see your function pasted-in.
So it will be inline just because of the inline
keyword, and forced with the always_inline
attribute even if the compiler would have refused to inline it because of function size for instance.
Word of advice: know what you're doing when including a .c
file from another one. Some build systems/makefiles just scan the directories looking for files called *.c
so they can compile them separately. Putting a possibly non-compiling C file there can make the build fail, and if it builds, you could have duplicate symbols when linking. Just don't do this.
If you want to do this, put your function in a .h
file and declare it static
so it won't fail the link if included in many .c files (each function will be seen as different)