Article View: comp.std.c
Article #1307Re: const arrays in prototypes
From: Benjamin Zhu
Date: Sat, 26 May 1990 23:54
Date: Sat, 26 May 1990 23:54
45 lines
2222 bytes
2222 bytes
In article <1990May26.164834.4211@jarvis.csri.toronto.edu> norvell@csri.toronto.edu (Theo Norvell) writes: >In article <1356@crabcake> zhu@crabcake.cs.jhu.edu (Benjamin Zhu) writes: >>In article <2781@sunset.MATH.UCLA.EDU> pmontgom@euphemia.math.ucla.edu (Peter Montgomery) writes: >>> Suppose instead that I am passing an array argument. If I >>>put "const" before the declaration, then I am stating that the data >>>will not be modified. How do I specify that the pointer to the array >>>will not be altered within the subroutine? >> >> Use the following prototype instead: >> >> void DISALLOW(const int ** const mat) >> >> It's fairly self-explanatory. Add const before mat, indicating that >> the pointer is also constant. >> >>Benjamin Zhu > >Perhaps you mean > void DISALLOW( const int (*const mat)[2] ) >But this is UGLY. > OK, this one would work, though someone might think it is ugly. >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. > 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? >Theo Norvell Benjamin Zhu +=========================================================================+ +Disclaimer: + + I do not represent Johns Hopkins, Johns Hopkins does not + + represent me either. + +==========================================================================
Technical Details
Message-ID:
<1359@crabcake>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!aplcen!haven!umd5!crabcake!zhuReferences:
<2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!aplcen!haven!umd5!crabcake!zhu From: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Newsgroups: comp.std.c Subject: Re: const arrays in prototypes Message-ID: <1359@crabcake> Date: 26 May 90 23:54:11 GMT References: <2781@sunset.MATH.UCLA.EDU> <1356@crabcake> <1990May26.164834.4211@jarvis.csri.toronto.edu> Reply-To: zhu@crabcake.cs.jhu.edu (Benjamin Zhu) Followup-To: comp.std.c Organization: JHU Computer Science Dept -- Town of Solitude Lines: 45