Groovy hepcat Arthur Rinkel was jivin' on Wed, 18 Jun 97 13:31:05 GMT
in comp.lang.c.
int pointer to int array again's a cool scene! Dig it!
Quote:
>I thank all people who replied so quickly to my msg, but I forgot to mention
>one thing: it's a 2-dimensional array of integers.
Doesn't matter. It still works the same, nomatter how many
dimentions it has. An int is an int is an int, whether it is in a nine
million six hundred and seventy three dimentional array or all on it's
lonesome. :)
An int pointer will always point to an int. That's all you need to
remember.
Quote:
>Some extra info: the array of integers are being used in a couple of
>functions, so I just want to pass the pointer (to this array) to those
>functions. Now I know the value of the "2nd dimension" ([][this_one]), which
>is btw variable and is passed to the functions as well. Now I tried to define
>the function with the pointer to the array and the value of the "2nd
>dimension" something like this (it only doesn't work):
You don't need to define the subscripts of array arguments. But if
you do, the subscript should be integral constants, not variables.
In fact, you could pass a pointer to the data type of the array (ie.
in this case, pointer to int).
Quote:
>int matrix_func(int matrix[][n], int nr_i)
One more thing: if I were you I'd pass the bounds of both dimentions
of the array to the function. For example:
int matrix_func(int *matrix, int width, int height);
#define ARRAY_WIDTH 80
#define ARRAY_HEIGHT 25
int *array;
array = malloc(ARRAY_WIDTH * ARRAY_HEIGHT * sizeof(int));
... /* do something to the data array points to */
matrix_func(array, ARRAY_WIDTH, ARRAY_HEIGHT);
This ensures matrix_func() knows the dimentions of the array so it
doesn't try to access data beyond the end of the array.
----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----
-------------- Shaggy was here! ---------------
http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============