1

What is the difference between these two statements:

void (*p) (void *a[],int n)

and

void *(*p[]) (void *a, int n)
4
  • 9
    cdecl.org Commented Dec 23, 2010 at 9:02
  • so both are syntactical erroneous? Commented Dec 23, 2010 at 9:12
  • i dont think so..can you give some reason.. Commented Dec 23, 2010 at 9:13
  • @Robert, @prp - cdecl is an odd tool, and perhaps I should have offered some more explanation. For cdecl to parse these declarations, you need to type explain in front of it, and remove the names of the arguments (a practice I do with function pointers anyway, but which C should normally parse perfectly fine). cdecl doesn't like them for no good reason I know of, but will give you the right answer if you take them out. Commented Dec 23, 2010 at 9:16

3 Answers 3

8
$ cdecl
void (*p) (void *a[],int n);
declare p as pointer to function that expects (a as array of pointer to void, n as int) returning void;
void *(*p[]) (void *a, int n);
declare p as array of pointer to function that expects (a as pointer to void, n as int) returning pointer to void;
Sign up to request clarification or add additional context in comments.

1 Comment

Does your cdecl handle parameter names, or did you just edit the I/O to be nicer to read? And if the former, where can I find a copy of this?
2

there is beautiful way of comprehending such type of complex declaration in Expert_C_Programming_Deep_C_Secrets_by_Peter_van_der_Linden on page 71.

According to him :

Declarations in c are boustrophedonically, i.e alternating right-to-left with left-to-right. Have a look at this snapshot

How-to-read-c-declaration

The ebook is available on google if you know how to download it.

Comments

0

void (*p) (void *a[],int n) p is the variable name. Remove p from the above line void ( * )(void *a[],int n) . So p is of this type. This is a pointer of a function. So p is a pointer to the function with that signature. So p is a pointer to a function which return void and takes array of 'void pointers' and int as the parameter.

void *(*p[]) (void *a, int n) [] has more precedence than *. So p is an array. remove p[] the above. So p is an array of void( * )(void *a[],int n)

So here p is an array of pointers to function which return void and takes array of 'void pointers' and int as the parameter.

1 Comment

Please stop linking to your website in your answers. Your answer should be as succinct as possible, adding a self-promoting link adds nothing to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.