What does this typedef statement mean?

Solution 1:

It's declaring several typedefs at once, just as you can declare several variables at once. They are all types based on int, but some are modified into compound types.

Let's break it into separate declarations:

typedef int int_t;              // simple int
typedef int *intp_t;            // pointer to int
typedef int (&fp)(int, ulong);  // reference to function returning int
typedef int arr_t[10];          // array of 10 ints

Solution 2:

typedef int int_t, *intp_t, (&fp)(int, mylong), arr_t[10];

is equivalent to:

typedef int int_t;
typedef int *intp_t;
typedef int (&fp)(int, mylong);
typedef int arr_t[10];

There is actually a similar example in the C++11 standard:

C++11 7.1.3 The typedef specifier

A typedef-name does not introduce a new type the way a class declaration (9.1) or enum declaration does.Example: after

typedef int MILES , * KLICKSP ;

the constructions

MILES distance ;
extern KLICKSP metricp ;

are all correct declarations; the type of distance is int that of metricp is “pointer to int.” —end example

Solution 3:

If you have the cdecl command, you can use it to demystify these declarations.

cdecl> explain int (&fp)(int, char)
declare fp as reference to function (int, char) returning int
cdecl> explain int (*fp)(int, char)
declare fp as pointer to function (int, char) returning int

If you don't have cdecl, you should be able to install it in the usual way (e.g. on Debian-type systems, using sudo apt-get install cdecl).