Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!nbires!vianet!devine From: devine@vianet.UUCP (Bob Devine) Newsgroups: comp.lang.c Subject: Re: array declarations.... Message-ID: <236@vianet.UUCP> Date: Wed, 23-Sep-87 15:37:24 EDT Article-I.D.: vianet.236 Posted: Wed Sep 23 15:37:24 1987 Date-Received: Sat, 26-Sep-87 05:27:58 EDT References: <9444@brl-adm.ARPA> Organization: Western Digital, Boulder Tech Ctr Lines: 66 Summary: table of declarations through 3 levels > 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 */