const arrays in prototypes

Benjamin Zhu zhu at crabcake.cs.jhu.edu
Wed May 30 00:04:11 AEST 1990


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:
>
>>>Perhaps you mean
>>>	void DISALLOW( const int (*const mat)[2] )
>>>But this is UGLY.
>
>It's as ugly as any other solution, and as ugly as most of C.
>
>>>Is the following a solution?
>>>	typedef const int const_matrix[2][2] ;
>>>	...
>>>	void DISALLOW( const const_matrix mat )
>>>If not, I'm sure someone will point out why.
>
>This is also valid.
>But you know the net.  Even if it's a solution, we can still trust
>someone to point out why it isn't.  ;-)
>In article <1359 at crabcake> zhu at crabcake.cs.jhu.edu (Benjamin Zhu) writes:
>>	Nope. In this case, "const" has been used twice, i.e., it
>>	is duplicatedly declared, which I believe is illegal in
>>	Ansi stardard.  Moreover, I fail to notice any semantical
>>	difference between "const_matrix" and "const const_matrix".
>>	Maybe you mean something else?
>Mr. Zhu, you have gotten this one wrong twice.  Looks like you should
>take a vacation from answering questions, until you're more alert.

	Wait a second. Let's see what you comment.

>
>typedef const int const_matrix[2][2] ;
>means that a variable of type const_matrix will have constant elements.
>void DISALLOW( const const_matrix mat )
>means that the pointer "mat" is a constant pointer.
>So the result is a constant pointer to constant elements.
>The two "const"s do not duplicate each other.

	No, I believe I am correct. Haven't you confused an array with
	a pointer? An array has to be treeted as a single object. So
	to define

		typedef	const int const_matrix[2][2];
		const const_matrix mat;

	is analogous to define

		typedef const int const_int;
		const const_int number;

	Of course the two const's duplicate each other. If you take
	my arguments, what's the semantical difference then? OK, if
	you insist that const duplication is allowed, then there IS
	some difference.

	I am not flaming you. Would you kindly test what you say, or
	at least check the references before you jump on someone?
>
>-- 
>Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
>Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.

Benjamin Zhu

+=========================================================================+
+Disclaimer:								  +
+	I do not represent Johns Hopkins, Johns Hopkins does not	  +
+	represent me either.						  +
+==========================================================================



More information about the Comp.std.c mailing list