Function Assignment Pointer

Why is an assignment without '&' compiled in the following code? I compiled the code with GCC 3.4.6. Is assignment correct without &, or is it a “function” of GCC?

void func() {
}

int main() {
  typedef void (*F)();

  F f;
  f = &func; // the way of assigning pointer to function.
  f = func;  // this is also working.

  (*f)();

  return 0;
}
+5
source share
1 answer

This is normal. Both statements are completely equivalent. The lvalue function is converted to a function pointer through a standard conversion. §4.3 / 1:

A value l of type of function T can be converted to an r-value of type "pointer to T". The result is a pointer to a function.

+13
source

All Articles