[comp.lang.c] array declarations....

GJWELYCH%SUNRISE.BITNET@wiscvm.wisc.EDU (09/23/87)

hi all,
   This may seem to be a simple and stupid question, but I can't find
an answer to it. Both the prof. and the class were wondering how you
declare a pointer to an array of pointers of type int.
   What we finally thought of is
       int *(* x)[5];
but, we aren't sure.....
If this is incorrect, could you please tell me the correct answer, and
explain what int *(* x)[5]; REALLY means....

                          Thanks in advance,
                          Greg Welych

p.s.:  please respond directly to me, and if wanted, I'd be willing to post
       a summary.

BITNET address:  GJWELYCH@SUNRISE.BITNET
EDU address (if reachable): GJWELYCH@AMAX.NPAC.SYR.EDU   or
                            GJWELYCH@CM1.NPAC.SYR.EDU    or
                            GJWELYCH@SFX.NPAC.SYR.EDU

swh@hpsmtc1.UUCP (09/23/87)

Re: Array of pointers

I ran your request through the 'cdecl' utility and got:

me>  explain int *(* x)[5]
it>  declare x as pointer to array 5 of pointer to int

Hope this clarifies.

---------------------
Steve Harrold			...hplabs!hpsmtc1!swh
				HPG200/13
				(408) 447-5580
---------------------

devine@vianet.UUCP (Bob Devine) (09/23/87)

> could you please explain what int *(* x)[5]; REALLY means....

  C type declarations ARE quite confusing when you go more than two
levels deep.  Chris Torek wrote a nice program called "cdecl" that
will interpret declarations.  Below is a table that may help in
identifying what a declaration is.

  The general rule for reading one is "start in the middle and work
towards the ends".  In more detail,

	1. start with the identifier
	2. look to the right for brackets or parentheses
	3. look to the left for asterisks
	4. remember that parentheses group
	5. finally, look at the type (eg. int)


Bob Devine

	C TYPE DECLARATIONS
	-------------------

int	i;	/* int */
int	*p;	/* ptr to int */
int	a[];	/* array of int */
int	f();	/* func returns int */

int	**pp;		/* ptr to ptr to int */
int	(*pa)[];	/* ptr to array of int */
int	(*pf)();	/* ptr to func returns int */
int	*ap[];		/* array of ptr to int */
int	aa[][];		/* array of array of int */
int	af[]();		/* array of func returns int ILLEGAL */
int	*fp();		/* func returns ptr to int */
int	*fa()[];	/* func returns array of int ILLEGAL */
int	ff()();		/* func returns func returns int ILLEGAL */

int	***ppp;		/* ptr to ptr to ptr to int */
int	(**ppa)[];	/* ptr to ptr to array of int */
int	(**ppf)();	/* ptr to ptr to func returns int */
int	*(*pap)[];	/* ptr to array of ptr to int */
int	(*paa)[][];	/* ptr to array of array of int */
int	(*paf)[]();	/* ptr to array of func returns int ILLEGAL */
int	*(*pfp)();	/* ptr to func returns ptr to int */
int	(*pfa)()[];	/* ptr to func returns array of int ILLEGAL */
int	(*pff)()();	/* ptr to func returns func returns int ILLEGAL */

int	**app[];	/* array of ptr to ptr to int */
int	(*apa[])[];	/* array of ptr to array of int */
int	(*apf[])();	/* array of ptr to func returns int */
int	*aap[][];	/* array of array of ptr to int */
int	aaa[][][];	/* array of array of array of int */
int	aaf[][]();	/* array of array of func returns int ILLEGAL */
int	*afp[]();	/* array of func returns ptr to int ILLEGAL */
int	afa[]()[];	/* array of func returns array of int ILLEGAL */
int	aff[]()();	/* array of func returns func returns int ILLEGAL */

int	***fpp();	/* func returns ptr to ptr to int */
int	(*fpa())[];	/* func returns ptr to array of int */
int	(*fpf())();	/* func returns ptr to func returns int */
int	*fap()[];	/* func returns array of ptr to int ILLEGAL */
int	faa()[][];	/* func returns array of array of int ILLEGAL */
int	faf()[]();	/* func returns array of func returns int ILLEGAL */
int	*ffp()();	/* func returns func returns ptr to int ILLEGAL */
int	*ffa()()[];	/* func returns func returns array of int ILLEGAL */
int	fff()()();	/* func returns func returns func returns int ILLEGAL */

dph@beta.UUCP (David P Huelsbeck) (09/24/87)

In article <11480007@hpsmtc1.HP.COM> swh@hpsmtc1.HP.COM (Steve Harrold) writes:
>Re: Array of pointers
>
>I ran your request through the 'cdecl' utility and got:
>
>me>  explain int *(* x)[5]
>it>  declare x as pointer to array 5 of pointer to int
>
>Hope this clarifies.
>
>---------------------
>Steve Harrold			...hplabs!hpsmtc1!swh
>				HPG200/13
>				(408) 447-5580
>---------------------


This looks like a dandy tool.

Where can I get it?

Thanks in advance.

	David Huelsbeck
	{cmcl2,ihnp4}!lanl!dph
	dph@lanl.gov.arpa

chris%mimsy.uucp@ROME.UCI.EDU (Chris Torek) (09/28/87)

In article <236@vianet.UUCP> devine@vianet.UUCP (Bob Devine) writes:
>... Chris Torek wrote a nice program called "cdecl" that
>will interpret declarations.

Although I have distributed it in the past, I did not write it.
I had the author's name somewhere in my mail, but I cannot find
it now.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris

devine@vianet.UUCP (Bob Devine) (09/28/87)

In article <8782@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes:
> In article <236@vianet.UUCP> devine@vianet.UUCP (Bob Devine) writes:
> >... Chris Torek wrote a nice program called "cdecl" that
> >will interpret declarations.
> 
> Although I have distributed it in the past, I did not write it.
> I had the author's name somewhere in my mail, but I cannot find
> it now.

  Sorry for the misattribution.  The author of "cdecl" is Graham Ross.

Bob