C's syntax (was Re: Python Formatted C Converter (PfCC))

Duncan Booth duncan at rcp.co.uk
Tue Oct 24 04:39:51 EDT 2000


wolfson at midway.uchicago.edu (Ben Wolfson) wrote in 
<Bi7J5.414$v3.4961 at uchinews>:
>So with
>
>int (*a)[5];
>
>you start with a)[ and proceed outwards?
>

One of the best description of this comes out of Microsoft's manuals (see 
http://msdn.microsoft.com/library/devprods\vs6\visualc/vclang/_clang_interp
reting_more_complex_declarators.htm for the source of this excerpt):
[I don't believe it! Microsoft actually have backslash separators in their 
URL!]

A simple way to interpret complex declarators is to read them “from the 
inside out,” using the following four steps: 

1. Start with the identifier and look directly to the right for brackets or 
parentheses (if any).

2. Interpret these brackets or parentheses, then look to the left for 
asterisks.

3. If you encounter a right parenthesis at any stage, go back and apply 
rules 1 and 2 to everything within the parentheses.

4. Apply the type specifier. 

char *( *(*var)() )[10];
 ^   ^  ^ ^ ^   ^    ^
 7   6  4 2 1   3    5

In this example, the steps are numbered in order and can be interpreted as 
follows: 

The identifier var is declared as

1. a pointer to

2. a function returning

3. a pointer to

4. an array of 10 elements, which are

5. pointers to

6. char values. 




More information about the Python-list mailing list