C function pointer syntax

I explain this in my answer to Why was the C syntax for arrays, pointers, and functions designed this way?, and it basically comes down to:

the language authors preferred to make the syntax variable-centric rather than type-centric. That is, they wanted a programmer to look at the declaration and think "if I write the expression *func(arg), that'll result in an int; if I write *arg[N] I'll have a float" rather than "func must be a pointer to a function taking this and returning that".

The C entry on Wikipedia claims that:

Ritchie's idea was to declare identifiers in contexts resembling their use: "declaration reflects use".

...citing p122 of K&R2.


This structure reflects how a normal function is declared (and used).

Consider a normal function definition:

int foo (int bar, int baz, int quux);

Now consider defining a function pointer to a function of the same signature:

int (*foo) (int, int, int);

Notice how the two structures mirror each other? That makes *foo much easier to identify as a function pointer rather than as something else.

Tags:

C

Declare