This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello!
I want some functions to be inlined directly into the final code.
This works well using the inline keyword, if function declaration, definition and call are in the same source file, like:
inline void test( void );
void main(void)
{
test();
}
inline void test( void )
{
...
}
But when I move the definition to a different source file and declare the function as external like this:
extern inline void test( void );
I get the error function "test" was referenced but not defined
at the declaration line
and the warning function "test" was declared but never referenced
at the definition line.
What am I doing wrong?
I believe this is just how the compiler operates, when using a function inline the function body itself must exist within the each module (C file) it is being called inline. I believe this has to do with how the compilation and linking stages are seperate, to generate a complete object file with functions that are embedded inline with the rest of the object file they would have to be available to the compiler at the time of compilation. If you have a function in a seperate C file as extern, it would not be available to the compiler at compile time, it would be generated later when the compiler runs on the C file that contains the function body and built into the end executable by the linker, thus it could not be properly inlined at the compilation step. In other words I do not believe the linker is capible of inlining functions, thus an inline function would have to be local to the compiled file.
The solution to your problem would be to either not inline the function, or have the inline function duplicated in the C files that it is needed as inline.
Thanks for the response.
It makes sense when you think about it...
Looks like I have to go back to preprocessor-macros again.
Regards,
Horst