S
Snis Pilbor
Hello,
Is there any actual difference between calling a function directly
by name, vs. calling it by a function pointer which points to it? I
read at the FAQ that the function name can be thought of as decaying to
a pointer, but is this *literally* true?
The reason I'm wondering is because I'd like to do the following sort
of optimization. Suppose deep in a time-sensitive function I have
something like
if ( global_boolean )
this_function();
else
that_function();
Where global_boolean is, as the name suggests, a global boolean which
changes from time to time due to things outside the function in
question, and infrequently. My idea is I could just make a global
function pointer, global_fncptr, and change the above 4 lines to
(*global_funcptr)();
Then wherever global_boolean were changed, I would also change
global_funcptr accordingly. Assuming global_boolean gets changed much
less frequently than the time-sensitive function gets called, it
intuitively seems like this will save time needlessly checking the
value of global_boolean. But that's assuming that calling my functions
with the global pointer is identical to calling them by name.
Thanks for any insight you can give on this =)
Snis Pilbor
Is there any actual difference between calling a function directly
by name, vs. calling it by a function pointer which points to it? I
read at the FAQ that the function name can be thought of as decaying to
a pointer, but is this *literally* true?
The reason I'm wondering is because I'd like to do the following sort
of optimization. Suppose deep in a time-sensitive function I have
something like
if ( global_boolean )
this_function();
else
that_function();
Where global_boolean is, as the name suggests, a global boolean which
changes from time to time due to things outside the function in
question, and infrequently. My idea is I could just make a global
function pointer, global_fncptr, and change the above 4 lines to
(*global_funcptr)();
Then wherever global_boolean were changed, I would also change
global_funcptr accordingly. Assuming global_boolean gets changed much
less frequently than the time-sensitive function gets called, it
intuitively seems like this will save time needlessly checking the
value of global_boolean. But that's assuming that calling my functions
with the global pointer is identical to calling them by name.
Thanks for any insight you can give on this =)
Snis Pilbor