const arrays in prototypes

diamond@tkovoa diamond at tkou02.enet.dec.com
Wed May 30 12:17:38 AEST 1990


In article <1373 at crabcake> zhu at crabcake.cs.jhu.edu (Benjamin Zhu) writes:
>In article <1745 at tkou02.enet.dec.com> diamond at tkou02.enet.dec.com (diamond at tkovoa) writes:
>>In article <1990May26.164834.4211 at jarvis.csri.toronto.edu> norvell at csri.toronto.edu (Theo Norvell) writes:
>>>>Is the following a solution?
>>>>	typedef const int const_matrix[2][2] ;
>>>>	void DISALLOW( const const_matrix mat )

Please note that this "mat" is a parameter.  Therefore its type is a
pointer, not an array.

ND>>... a variable of type const_matrix will have constant elements.
ND>>... the pointer "mat" is a constant pointer.
ND>>The two "const"s do not duplicate each other.

BZ>	No, I believe I am correct. Haven't you confused an array with
BZ>	a pointer? An array has to be treeted as a single object. So
BZ>	to define
BZ>		typedef	const int const_matrix[2][2];
BZ>		const const_matrix mat;
BZ>	is analogous to define
BZ>		typedef const int const_int;
BZ>		const const_int number;
BZ>	Of course the two const's duplicate each other.

This "mat" is not a parameter, so its type is indeed an array.
Yes, for arrays, these two "const"s duplicate each other.
This is a different problem from the one Mr. Norvell asked.

>	I am not flaming you. Would you kindly test what you say, or
>	at least check the references before you jump on someone?

Both Mr. Zhu and I missed what appears to be yet another bug in the
standard.  Someone asked a question via e-mail, and in attempting
to answer, I found the odd wording in the standard:
In section 3.7.1, "On entry to the function", argument values and
parameter types are adjusted.  So the type is adjusted at run time!!!!
In section 3.5.4.3, parameter types are not adjusted at all in
prototypes for function declarators!!!!

Therefore three interpretations are now necessary.  (1) should the
adjustment be done at compilation/translation/whatever time instead
of run time; (2) should adjustments also be done in declarators;
and (3) do adjustments occur before or after the outer "const" is
applied to the parameter.

-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.



More information about the Comp.std.c mailing list