This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: Printing a 2D array in a C program
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: Neven Sajko <nsajko at gmail dot com>
- Cc: Jan Kratochvil <jan dot kratochvil at redhat dot com>, gdb at sourceware dot org
- Date: Fri, 04 Mar 2016 19:34:43 +0100
- Subject: Re: Printing a 2D array in a C program
- Authentication-results: sourceware.org; auth=none
- References: <CAL+bK4NidroyapZhGvtVVsiCbu4=Hz56mF4_oU3iXM-rvqY_xw at mail dot gmail dot com> <20160304144231 dot GA7767 at host1 dot jankratochvil dot net> <CAL+bK4MV9ZLkon2PONYRpF0506P8zE3=Ukm0F1zpVDHd2HpAtw at mail dot gmail dot com>
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."