const arrays in prototypes
Benjamin Zhu
zhu at crabcake.cs.jhu.edu
Sun May 27 09:54:11 AEST 1990
In article <1990May26.164834.4211 at jarvis.csri.toronto.edu> norvell at csri.toronto.edu (Theo Norvell) writes:
>In article <1356 at crabcake> zhu at crabcake.cs.jhu.edu (Benjamin Zhu) writes:
>>In article <2781 at sunset.MATH.UCLA.EDU> pmontgom at 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. +
+==========================================================================
More information about the Comp.std.c
mailing list