const arrays in prototypes

Benjamin Zhu zhu at crabcake.cs.jhu.edu
Sun May 27 04:04:11 AEST 1990


In article <2781 at sunset.MATH.UCLA.EDU> pmontgom at euphemia.math.ucla.edu (Peter Montgomery) writes:
>[lots of stuffs deleted]
>	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?  For example,
>*/
>
>void DISALLOW(const int mat[2][2])
 
	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.

>{
>    mat++;		/* I want to forbid this usage.		       */	
>    mat[0][1] = 4;	/* Gcc 1.37.1 properly warns about this line.  */
>}
>
>--
>--------
>        Peter Montgomery
>        pmontgom at MATH.UCLA.EDU 
>	Department of Mathematics, UCLA, Los Angeles, CA 90024

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