[comp.lang.c] interpreting type declarations

ftw@datacube.UUCP (07/24/87)

pal@calmasd.UUCP writes:

> I have just seen both the "right-left" rule and the "left-right" rule
> in two recent net articles for interpreting type declarations like
> 	foo **bar[5][6];
> 	int *farkle()[];
> Will the real rule please stand up.
> Thanks.

> -- 
> pal@calmasd.GE.COM   or  ...!sdcsvax!calmasd!pal

I would like to start the "Inside Out" camp.  More specifically, the
declarations follow C's rules of precedence, just like for expressions.
In the first example, array indexing has precedence over indirection,
so "bar" is a 5 by 6 array of pointers to pointers to a "foo".

The same hold true for the second example.  To wit: farkle is a function
that returns an array of pointers to an int.  The C compiler on the Pyramid
here swallows it; but a 68K cross compiler we have doesn't (it cries "syntax
error at the sight of the brackets).

The second declaration seems to defy the semantics of C, given the way I
just explained it.  For instance, an array name by itself is a synonym for
the address of its first member, and does not refer to the entire array.
Therefore, "array name" is not an lvalue, and cannot be assigned to.  The
compiler on the Pyramid must be making the assumption that what I *really*
intend is to return a pointer, which is what will happen if I wrote
a "farkle" function and said "return (array_name);" at the bottom.  It's
letting me get away with a sloppy declaration.


				Farrell T. Woods 

Datacube Inc. Systems / Software Group	4 Dearborn Rd. Peabody, Ma 01960
VOICE:	617-535-6644;	FAX: (617) 535-5643;  TWX: (710) 347-0125
UUCP:	ftw@datacube.COM,  ihnp4!datacube!ftw
	{seismo,cbosgd,cuae2,mit-eddie}!mirror!datacube!ftw