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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 (
.cfile). In another compilation unit (another.cfile), 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
.cfile than the currently compiled.cfile.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:
fis defined in filea.ha.his included by C filesx.candy.cx.ctakes the address offand stores it into a global variablef_addry.ctakes the address offand compares it for identity to the value stored inf_addrfalse, despite the fact that on a different level of abstraction it is the very same functionfIf 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.