Article View: comp.std.c
Article #1325Re: const arrays in prototypes
From: diamond
Date: Wed, 30 May 1990 02:17
Date: Wed, 30 May 1990 02:17
48 lines
2885 bytes
2885 bytes
In article <1373@crabcake> zhu@crabcake.cs.jhu.edu (Benjamin Zhu) writes: >In article <1745@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes: >>In article <1990May26.164834.4211@jarvis.csri.toronto.edu> norvell@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@tkou02.enet.dec.com Proposed group comp.networks.load-reduction: send your "yes" vote to /dev/null.
Technical Details
Message-ID:
<1752@tkou02.enet.dec.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!apple!decwrl!shlump.nac.dec.com!tkou02.enet.dec.com!diamondReferences:
<2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu> <1359@crabcake> <1745@tkou02.enet.dec.com> <1373@crabcake>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!usc!apple!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: <1752@tkou02.enet.dec.com> Date: 30 May 90 02:17:38 GMT References: <2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu> <1359@crabcake> <1745@tkou02.enet.dec.com> <1373@crabcake> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 48