Sunday, January 24, 2010

C gibberish

When reading a question in the Linux Kernel Mailing lists section linux-c-programming, someone ask about the means of this code

char (*pa())[4];

Someone else ask him to use cdcel a small utility that translate C syntax into human readable words. For example consider this code

int (*sched_callback) (pid_t, struct sched_param*);

this means

declare sched_callback as pointer to function (pid_t, pointer to struct sched_param) returning int

Here a short description about cdecl
Cdecl is a program which will turn English-like phrases such as "declare foo as array 5 of pointer to function returning int" into C declarations such as "int (*foo[5])()". It can also translate the C into the pseudo-English. And it handles typecasts, too. Plus C++. And in this version it has command line editing and history with the GNU readline library.

By the way, the answer of his question according to cdecl is

declare pa as function returning pointer to array 4 of char

Give it a try, it's perfect for deep understanding the C language.

http://www.cdecl.org/