help with a MESSY C definition!!?

Blair P. Houghton bph at buengc.BU.EDU
Tue Nov 22 11:13:16 AEST 1988


In article <207600008 at s.cs.uiuc.edu> dlee at s.cs.uiuc.edu writes:
>
>I usually don't have any trouble with C, but this is a glaring exception:  I
>need the syntax of definition for an array (of arbitrary size) of pointers to
>functions returning pointers to integer (HOW'S *THAT* FOR A DOOZY!!!).  My
>closest (possibly correct) guess follows:
>
>	int *(*opfuncs[])() = {
>		.
>		.
>		.
>	};

Let's play precedence:

opfuncs[]		is an array;
*opfuncs[]		is an array of pointers
(*opfuncs[])()		is an array of pointers to function
*(*opfuncs[])()		is an array of pointers to function returning pointer
int *(*opfuncs[])()	is an array of pointers to function returning pointer
				to int.

I'll buy it.

Now, prove that 

	(int *(*)())

is unambiguously "cast to pointer to function returning pointer
to int" and never misinterpreted as "cast to function returning pointer
to pointer to int," whatever the hell that means...

				--Blair
				  "Take two asterisks and call me
				   in the morning."



More information about the Comp.lang.c mailing list