formal parameter question

utzoo!decvax!harpo!eagle!mhtsa!alice!npoiv!eisx!pyuxll!jse utzoo!decvax!harpo!eagle!mhtsa!alice!npoiv!eisx!pyuxll!jse
Mon Jan 31 15:46:58 AEST 1983


Suppose you are given the following formal parameter declaration:

	int	(*x)[];

What type is x?

My first thought was 'pointer to pointer to int', because
page 95 of K&R says that 's[]' and '*s' are equivilent
as formal paramters in a function definition, so I converted it
to *(*x).  But this is wrong.

The K&R book would seem to say that this is a multi-dimensional array,
except that it says you are required to give the constant between
the brackets (pages 105 and 195).

The vax C compiler seems to treat it as a multi-dimensional array, but one
that is declared

	int	x[][0];

although you can't use this declaration yourself (it will let
you use int (*x)[0] tho).  So x[0][0] and x[1][0] reference
the same location!

In the context in which I encountered this declaration, it was intended
that x be a pointer to an array, so I tried to pass the address of
the first element of the array but lint complained of a type mismatch.

Is 'int (*x)[]' legitimate?  I know 'int (*x)[5]' is legitimate,
declaring x to be a pointer to an array of 5 integers (x+1 points to
the next array of 5 integers).  But I don't see why I shouldn't
be able to convert 'int (*x)[]' to 'int **x'.  Is there any reason
why you would really want to use 'int (*x)[]' for pointer to array
rather than the simpler 'int *x'?


I would appreciate it if someone can provide further insight.

	Jan Edler	pyuxll!jse	(abi piscataway)
			cmcl2!edler	(nyu)
			edler at nyu.arpa	(I think this works)



More information about the Comp.lang.c mailing list