Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of complex C syntax [duplicate]

Tags:

c++

c

pointers

Possible Duplicate:
What does this C statement mean?

What does this expression mean?

char *(*c[10])(int **p);
like image 260
user1285201 Avatar asked Mar 22 '12 06:03

user1285201


2 Answers

c is an array of 10 function pointers that return a char* and take a int** as an argument.

(*c[10])
   ^^^^ = array of 10

(*c[10])
 ^ = function pointer

So right now we have an array of 10 function pointers.

char *(*c[10])
^^^^^^ = returns a char*

char *(*c[10])(int** p)
               ^^^^^ = takes a int** as an argument

Array of 10 function pointers that return a char* and take a int** as an argument.

NOTE: If you write code like this you deserve to be slapped in the face.

like image 183
Marlon Avatar answered Nov 20 '22 07:11

Marlon


cdecl is a nice tool to translate C gibberish into English

$ cdecl explain 'char * (*c[10]) (int **)'
declare c as array 10 of pointer to function (pointer to pointer to int) returning pointer to char
like image 52
Bartosz Moczulski Avatar answered Nov 20 '22 09:11

Bartosz Moczulski