🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1315

Re: const arrays in prototypes

#1315
From: diamond
Date: Tue, 29 May 1990 01:44
36 lines
2087 bytes
In article <1990May26.164834.4211@jarvis.csri.toronto.edu> norvell@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@crabcake> zhu@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.

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.

-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
Proposed group comp.networks.load-reduction:  send your "yes" vote to /dev/null.
Technical Details
Message-ID: <1745@tkou02.enet.dec.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!tut.cis.ohio-state.edu!purdue!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamond
References: <2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu> <1359@crabcake>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!snorkelwacker!tut.cis.ohio-state.edu!purdue!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamond
From: diamond@tkou02.enet.dec.com (diamond@tkovoa)
Newsgroups: comp.std.c
Subject: Re: const arrays in prototypes
Message-ID: <1745@tkou02.enet.dec.com>
Date: 29 May 90 01:44:07 GMT
References: <2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu> <1359@crabcake>
Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa)
Organization: Digital Equipment Corporation Japan , Tokyo
Lines: 36