0

How the above declaration of function pointers work in C/C++. I first encountered this declaration while making use of the signal.h file in c programming.

  • 1
    [cdecl.org](http://cdecl.org/?q=void+%28*var_name%29%28data_type%29) – Igor Tandetnik Dec 11 '16 at 03:36
  • See the [Clockwise/Spiral Rule](http://c-faq.com/decl/spiral.anderson.html). – e0k Dec 11 '16 at 03:51
  • [`signal()`](https://linux.die.net/man/2/signal) is a wonderful and classic real life example used to teach how to read function declarations, specifically using pointers to functions. – e0k Dec 11 '16 at 03:53
  • Possible duplicate of [How do function pointers in C work?](http://stackoverflow.com/questions/840501/how-do-function-pointers-in-c-work) – taskinoor Dec 11 '16 at 03:56
  • I'm voting to close this question as off-topic because It's listed under section Important notes that may save you time of tag info of tag C – Danh Dec 11 '16 at 03:58
  • This is how you declare a pointer to a function. – Havenard Dec 11 '16 at 04:04

2 Answers2

2

This is a function pointer decalaration

void (*var_name)(int)

In this example, var_name is a pointer to a function taking one argument, integer, and that returns void. It's as if you're declaring a function called "*var_name", which takes an int and returns void; now, if *var_name is a function, then var_name must be a pointer to a function

Hardik Sanghvi
  • 416
  • 4
  • 12
0

http://cyan-lang.org/jose/courses/06-2/lc/Ponteiros-para-Funcoes.htm

It's in Portuguese, Example:

in C, we can declare a pointer to function with the syntax

void (* f) ();

In this case, f is a pointer to a function with no parameters and that returns void. F can point to a compatible function:

F = maximum;

Maximum is a function declared as

void max () {
    Puts ("Hi, I'm the max");
}

Maximum can be called from f using any of the syntax below.

(* F) (); / * Maximum call * /
F (); / * Maximum call * /
Gabriel Cesar
  • 391
  • 3
  • 7