Simple c question - pointer to array
    ed gokhman 
    esg at mtx5a.UUCP
       
    Sat May 31 07:29:00 AEST 1986
    
    
  
> Ok if i have a struct which is named in a typedef as T, I 
> know how to get an array of pointers to T:   T *a[20];
> what I want is a pointer to an array of T's.
Kurt,
All you need is to express the declaration in English
and then to convert it token by token. If precedence
of the i-th token is higher then (i-1)-th the result
of translation of first i-1 tokens must be parenthesized.
In order of decreasing precedence "valid" English tokens
and their C-conversions are (S stands for the string resulting
from the previous step in English-C conversion (possibly,
parenthesised)):
English					C
--------------------------------------------------
<name> is                               <name>
function returning                      S ()
array of  N                             S [ N ]
pointer to                              *S
===================================================
For example,
English                                 C
--------------------------------------------------
X is a pointer to an array of 20 Ts	...
a pointer to an array of 20 Ts          X
an array of 20 Ts                       *X
	> precedence of [] is higher then *, so
	>*X should be parenthesizied.
an array of 20 Ts                         (*X)
Ts                                      (*X)[]
...                                     T  (*X)[]
===================================================
Similarly,
 "X is a pointer to an array of 10 pointers
to functions returning pointers to arrays of 11 int"
would be    int (*(*(*X)[10])())[11]
    
    
More information about the Comp.lang.c
mailing list