Does C static inline function have identity at runtime?
Should I care about naming conflict of that constructs?
If the function is defined in .c
file? Is it same?
Does C static inline function have identity at runtime?
Static inline function has identity within a compilation unit if the compiler at least once chooses not to inline it, or if you take the address of the function.
The taken address is valid only in the current compilation unit (.c
file). In another compilation unit (another .c
file), the compiler will give you a different address.
As with any other function with body visible to the compiler, the code from the function might be fully or partially replicated in various places in the assembly code generated by the compiler.
A static inline function (as any static function) is not visible from any other .c
file than the currently compiled .c
file.
Should I care about naming conflict of that constructs?
Only if you take the address of a static inline function defined in a header file and do the following:
f
is defined in file a.h
a.h
is included by C files x.c
and y.c
x.c
takes the address of f
and stores it into a global variable f_addr
y.c
takes the address of f
and compares it for identity to the value stored in f_addr
false
, despite the fact that on a different level of abstraction it is the very same function f
If the function is defined in .c file? Is it same?
From C compiler viewpoint, it is exactly the same as defining the function in a header file and including the header file in the .c file. The compiler has no idea about header files, it only sees one continuous compilation unit. A header file is a concept that exists in the minds of programmers using the C language - this concept does not exist from the viewpoint of the C compiler.