Monday, October 23, 2006

Reading C type declarations

From, Steve Friedl's Unixwiz.net Tech Tips, unixwiz.net

" ...

Even relatively new C programmers have no trouble reading simple C declarations such as

int      foo[5];     // foo is an array of 5 ints
char *foo; // foo is a pointer to char
double foo(); // foo is a function returning a double

but as the declarations get a bit more involved, it's more difficult to know exactly what you're looking at.

char *(*(**foo[][8])())[]; // huh ????? 

It turns out that the rules for reading an arbitrarily-complex C variable declaration are easily learned by even beginning programmers (though how to actually use the variable so declared may be well out of reach).

This Tech Tip shows how to do it.

..."

read more ...

No comments: