logoalt Hacker News

nitrixtoday at 5:03 PM1 replyview on HN

Some more examples:

  int v, *w, x[5], *y[5], (*z[5])(int, int);
Where v is an int, w is a pointer, x is an array, y is an array of pointers, z is an array of function pointers, etc.

Similarly, typedef is also just a keyword in front of a regular declaration.

  int foo[5];
  typedef int foo[5];

  int bar(void);
  typedef int bar(void);
Now you can use `bar *` as a function pointer.

The entire language works like this.


Replies

arjviktoday at 6:02 PM

The way I've learned to read it is

    int v;
means that `v` is an `int`.

    int *w;
means that `*w` is an `int`, meaning `w` is a pointer to an `int`.

    int *y[5]
(note that `◌[]` has higher precedence than `*◌`, so this is `*(y[5])`) means that `*y[5]` is an `int`, so `y[5]` is a pointer to an `int`, meaning `y` is an array of `int` pointers.

    int (*(*kitchensink[5])(int, int))[6];
means that `(*(*kitchensink[5])(int, int))[6]` is an int, so

- `*(*kitchensink[5])(int, int)` is an array of `int`.

- `(*kitchensink[5])(int, int)` is a pointer to array of `int`.

- `kitchensink[5]` is a function pointer to a function that takes `(int, int)` and returns a pointer to an array of `int`.

- `kitchensink` is an array of function pointers to functions that take `(int, int)` and return a pointer to an array of `int`.

show 1 reply