Re: Printing a 2D array in a C program

Andreas Schwab <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <[email protected]>
Neven Sajko <[email protected]> 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, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.