In section 7.1.1 of the book “The C++ Programming Language” the author states:
“inline function still has a unique address and so do the static variables of an inline function”
I am confused. If I have an inline function then it can’t have address. Does this happen in C also?
The
inlineattribute is just a hint to the compiler that it should try to inline your function. It’s still possible to take the address of the function, and in that case the compiler will also need to emit a non-inline version.For example:
The above code prints
hellotwice.My
gcccompiler (with-O) emits code something like this:As you can see, there is first a call to
puts()and then a call toL__Z1fv()(which is the mangled name off()).