const arrays in prototypes
Theo Norvell
norvell at csri.toronto.edu
Sun May 27 06:48:34 AEST 1990
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 the
> the pointer is also constant.
>
>Benjamin Zhu
Perhaps you mean
void DISALLOW( const int (*const mat)[2] )
But this 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.
Theo Norvell
More information about the Comp.std.c
mailing list