K
Keith Thompson
Mark McIntyre said:Firstly the & is not neccessary - the name of a function is a pointer to
it.
More precisely, when a function name appears in an expression context,
it's implicitly converted to a pointer-to-function unless it's the
operand of a unary "&" or sizeof operator. (The latter results in a
constraint violation). Applying "&" to a function yields its address,
so inc and &inc are equivalent. The explicit "&" arguably makes it
clearer that you're taking the address of the function.
(This applies even on a function call; a function call operator's
first argument is a pointer-to-function.)
More importantly tho, since inc() is local to glfn1(), when you
return from glfn1, it disappears. Hence its address becomes invalid
and referencing it will probably cause a segfault. .
Maybe. The C standard says nothing about what happens to nested
functions when you leave the scope in which they're defined, since the
C standard says nothing about nested functions. The gcc documentation
will probably tell you more. <speculation>The code for the function
isn't going to go away, but the context for the call is going to be
gone; I don't know whether that's going to cause a segfault.
Conceivably there's no problem unless it makes uplevel references.
</speculation>