Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!mcnc!gatech!bloom-beacon!think!ames!amdcad!sun!imagen!auspyr!altnet!altos86!root
From: root@altos86.UUCP
Newsgroups: comp.lang.c
Subject: Re: can you 'splain this to me?
Message-ID: <369@altos86.UUCP>
Date: Fri, 17-Jul-87 14:31:27 EDT
Article-I.D.: altos86.369
Posted: Fri Jul 17 14:31:27 1987
Date-Received: Sat, 18-Jul-87 18:39:53 EDT
References: <966@lll-lcc.aRpA>
Reply-To: root@altos86.UUCP (LEAVE as csh! Dave Olson)
Distribution: na
Organization: Altos Computer Systems, San Jose, CA
Lines: 64

In article <966@lll-lcc.aRpA> booloo@lll-lcc.UUCP (Mark Boolootian) writes:
>~~~~~~
>In an article called "The C Programming Language" by Ritchie, et al, there
>is an example given that I can't seem to figure out.  The example is supposed
>to be a pointer to an array of pointers to functions, each retuning an int
>and its declaration is:
>			int (*(*funnyarray)[])();
>
>I don't know if it is possible to explain why this is what it is but I would
>appreciate any attempts (via email).  I can see what 
>			int (*f)()
>			   and
>			int (*g)[]
>are but the composition is confusing to me.  Actually I almost had it there
>for a moment but it just now slipped away again.  Thanks in advance.
>
>mb

typedef int (*pfri)();	/* Pointer to Function Returning Int	*/
typedef pfri apfri[];	/* Array of PFRI			*/
typedef apfri *papfri;	/* Pointer to APFRI			*/
	/* which is "funnyarray above" */

Combining, we get the more obscure declaration of `apfri' of
	(*apfri[])()
how?
	1.	take
			(*pfri)()
	2.	subsitute
			apfri[]
		in for "pfri" and get
			(*apfri[])()
		note that in this case extra parentheses are not needed,
		since [] binds more tightly than *

This can also be done with the next step, that of getting the more
obscure declaration of `papfri':
	1.	take
			(*apfri[])()
	2.	subsitute
			*papfri
		in for "apfri" and get
			(*(*papfri)[])()
		note that here the inner set of parens are absolutely
		necessary due to the fact that
			(**name[])()
		binds like
			(**(name[]))()
		which has a very different meaning: an array of pointers
		to functions returning pointers to functions returning
		integers...


typedef int (*pfri)();		/* Pointer to Function Returning Int */
typedef pfri (*pfrpfri)();	/* Pointer to Function Returning PFRI */

int (*(*pfrpfri))() ==		(**pfrpfri)()
array of these ==		(**apfrpfri[])()

--------------------------------------------------
Nathaniel Ingersoll
Altos Computer Systems, SJ CA
...!inhp4!elxsi!altos86!nate
public@ucscd.UCSC.EDU