Function call with different semantics

Given this code with 3 distinguishing features of a function:

void f(void){
   puts("OK");
}

int main(void){
   f();
  (*f)();
  (&f)();

  return 0;
}

The first is the standard way to call f,

the second is semantics for dereference function pointers,

but in the third, I apply the and operator to the function name and it seems to work fine.

What happens in the second and third cases?

Thank.

+5
source share
2 answers

Function calls are always made using function pointers. From section C99 6.5.2.2:

The expression indicating the function to be called must have a pointer to the function.

However, in almost all cases, the type of function decays into the type of the pointer function. From section C99 6.3.2.1:

, sizeof &, " " , " ".

, :

(&f)();
(&(*(&f)))();
(&f)();

. , , (f()) .

+8

. . . , , .

, . , , :

void AFunction();
void (*funcPtr)() = NULL;

funcPtr = AFunction; 
funcPtr = &AFunction;
+1

All Articles