I am having difficulty trying to understand what the following declaration means. Is this declaration standard?
double* (*p[3]) (void* (*)());
Can anyone help me to understand the meaning of this declaration?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Rule for reading hairy declarations: find the leftmost identifier and work outward, remembering that
()and[]bind before*, soT *a[N]is an array of pointers toT,T (*a)[N]is a pointer to an array ofT,T *f()is a function returning a pointer toT, andT (*f)()is a pointer to a function returning T. Since a function prototype may omit parameter names, you may see things likeT *[N]orT (*)(). The meaning is mostly the same1, just pretend that there’s an identifier of 0 length.Thus,
The important thing to take away here is that you are declaring
pas an array of..., not a function returning....What would such a beast look like in practice? Well, first, you need three functions to point to. Each of these functions takes a single parameter, which is a pointer to a function returning a pointer to void:
Each of
foo,bar, andbletchwould call the function passed to it and somehow return a pointer todouble.You would also want to define one or more functions that satisfy the parameter type for each of
foo,bar, andbletch:so if you called
foodirectly, you’d call it likeSo we could imagine a call like
1 – the difference is that in the context of a function parameter declaration,
T a[]andT a[N]are identical toT *a; in all three cases,ais a pointer toT, not an array ofT. Note that this is only true in a function parameter declaration. Thus,T *[]will be identical toT **.