From: Andreas Schwab <schwab@linux-m68k.org>
To: Neven Sajko <nsajko@gmail.com>
Cc: Jan Kratochvil <jan.kratochvil@redhat.com>, gdb@sourceware.org
Subject: Re: Printing a 2D array in a C program
Date: Fri, 04 Mar 2016 18:34:00 -0000 [thread overview]
Message-ID: <87k2lim6rg.fsf@linux-m68k.org> (raw)
In-Reply-To: <CAL+bK4MV9ZLkon2PONYRpF0506P8zE3=Ukm0F1zpVDHd2HpAtw@mail.gmail.com> (Neven Sajko's message of "Fri, 4 Mar 2016 17:15:26 +0100")
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."
next prev parent reply other threads:[~2016-03-04 18:34 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-04 14:27 Neven Sajko
2016-03-04 14:42 ` Jan Kratochvil
2016-03-04 16:15 ` Neven Sajko
2016-03-04 17:49 ` Jan Kratochvil
2016-03-04 18:24 ` Pedro Alves
2016-03-04 18:59 ` Jan Kratochvil
2016-03-04 19:16 ` Pedro Alves
2016-03-04 18:34 ` Andreas Schwab [this message]
2016-03-04 21:48 ` Neven Sajko
2016-03-04 22:16 ` Andreas Schwab
2016-03-05 0:59 ` Neven Sajko
2016-03-05 8:23 ` Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k2lim6rg.fsf@linux-m68k.org \
--to=schwab@linux-m68k.org \
--cc=gdb@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=nsajko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox