CBFalconer <cb********@yahoo.comwrites:
Keith Thompson wrote:
>CBFalconer <cb********@yahoo.comwrites:
... snip ...
>>
>>Rather hard to take a pointer to an inlined function.
Functions aren't inlined. Function calls are inlined. Inlining
a call doesn't prevent taking the address of the function (as
long as a non-inlined version of the function is kept).
That makes no sense to me. If you inline the following:
inline int sq(int a) {return a * a;}
you do not expect to waste any time assigning registers, creating a
stack marker, executing a call, etc. All you want to do is execute
that action in line.
Of course, that's the purpose of inlining. But it doesn't preclude
taking the function's address.
Let's ignore the "inline" keyword for the moment, and just consider
inlining as an optimization that might be performed by a pure C90
compiler. Given a function like the one you've defined:
int sq(int a) { return a * a; }
one *call* might be inlined:
int x = whatever;
int y = sq(x); /* sq(x) expanded to x * x */
while another call might be implemented as an ordinary function call.
So inlining is an attribute of a given function, call, not necessarily
of a function.
And it's still perfectly legal to take the address of the "sq"
function, and to use that address later in an indirect call. Such an
indirect call can't easily be inlined, which means that a function
body must be provided (unless the compiler can prove it's not
necessary).
The C99 inline specifier is an suggestion to the compiler to inline
calls to that function. Note that the standard doesn't forbid taking
the address of a function declared with the inline specifier. (If it
did, calls would be impossible, since a simple function call
implicitly takes the address of the function.)
If you declare (in C99):
inline int sq(int a) {return a * a;}
then you're suggesting that calls to sq should be as fast as possible
(see C99 6.7.4 for the exact wording), but you're *not* giving up the
possibility of computing and storing the address of sq.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"