pointers to arrays

Chris Torek chris at mimsy.UUCP
Fri Feb 17 02:31:36 AEST 1989


In article <19784 at uflorida.cis.ufl.EDU> thoth at beach.cis.ufl.edu
(Robert Forsman) writes:
>... Gordon Cross wants to take the address of an array....  My
>question is "what will you use this for?"

For whatever you like.  E.g.:

	f(ptr_to_array, number_of_arrays)
		int (*ptr_to_array)[30];
		int number_of_arrays;
	{
		int i;

		for (i = 0; i < number_of_arrays; i++)
			(*ptr++)[5] = 42;
	}

	foo()
	{
		int first[2][30];
		int second[30];

		f(first, 2);
		/* now first[0][5] = 42 and first[1][5] = 42 */

		f(&second, 1);
		/* now second[0][5] = 42 */

		...
	}

Without allowing `&array' you must write

		f((int (*)[30])second, 1);

which is after all rather silly.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list