Re: Printing a 2D array in a C program

Andreas Schwab
2016-03-04T18:34:50Z

Neven Sajko <nsajko@gmail.com> writes:

> In my question I asked about C (not C++), I even mentioned the
> gcc -std=gnu90 option.
>
> My code is thus:
>
> enum {
> sz = 17
> };
>
> void p(int m[sz][sz], int n) {
> int i;
> for (i=1; i<n; i++) {
> int j;
> for (j=i-1; 0<=j; j--) {
> m[i][j] = abs(3*m[i-1][j] +2*m[i][j+1]) % 9340506;
> }
> }
> }
>
> void f(int n) {
> int m[sz][sz];
>
> g(m, n);
>
> p(m, n);
>
> r(m, n);
> }
>
>
> So, when I am in f, `info locals` prints it like {{a11, ...,
> a1n}, ..., {an1, ..., ann}}.
> But in p `print *m` just gets me {a11, ..., a1n}.

This is correct, *m has the type int[sz]. If you want to print all
elements pointed to by m you need to use `print *m@sz'.

Andreas.

--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."