tmj
tmj

Reputation: 1868

What does this typedef statement do?

I was going through some code and am not able to understand the following piece of code. What does it do? What does it mean?

typedef void*(*fun)[2];
fun new_array;

Upvotes: 1

Views: 92

Answers (2)

Brian Bi
Brian Bi

Reputation: 119597

OK, basically, this is how typedef works: first imagine that the typedef isn't there. What remains should declare one or more variables. What the typedef does is to make it so that if you would declare a variable x of type T, instead it declares x to be an alias for the type T.

So consider:

void*(*fun)[2];

This declares a pointer to an array of void* of size 2. Therefore,

typedef void*(*fun)[2];

declares fun to be the type "pointer to array of void* of size 2". And fun new_array declares new_array to be of this type.

Upvotes: 5

Some programmer dude
Some programmer dude

Reputation: 409482

Following the clockwise/spiral rule, fun is a pointer to an array of two pointers to void.

Upvotes: 5

Related Questions