Article View: gnu.gdb.bug
Article #10127Re: Variable array problems.
From: ian
Date: Thu, 31 May 1990 04:39
Date: Thu, 31 May 1990 04:39
50 lines
1968 bytes
1968 bytes
I submitted a bug which wouldn't compile with gcc without a (gcc) bug fix.
Here is a revised bug report which will compile.
-----------------------------------array.c---------------------------
void foo (int, int [][]);
main()
{
int x[10][10];
int i, j;
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++)
x[i][j] = i * 10 + j;
foo(10, x);
}
void foo (int n, int x[n][n])
{
printf("%d\n", x[1][1]);
}
----------------------------------------------------------------------
Compiled with
gcc -g -o array array.c
GDB 3.5, Copyright (C) 1989 Free Software Foundation, Inc.
There is ABSOLUTELY NO WARRANTY for GDB; type "info warranty" for details.
GDB is free software and you are welcome to distribute copies of it
under certain conditions; type "info copying" to see the conditions.
Reading symbol data from /usr/u/ian/tmp/array...done.
Type "help" for a list of commands.
(gdb) b foo
Breakpoint 1 at 0x1c2: file array.c, line 14.
(gdb) r
Starting program: /usr/u/ian/tmp/array
Bpt 1, foo (n=10, x=(int (*)[1]) 0xfffb0c) (array.c line 15)
15 printf("%d\n", x[1][1]);
(gdb) p x[1][1]
$1 = 2
(gdb) next
11
Note that the p x[1][1] prints 2 instaed of 11. Also the argument x
should be reported as (int (*)[n]) or (int (*)[10]) and the array
indexing calculated accordingly.
Ian Dall.
Technical Details
Message-ID:
<9006010109.1775@munnari.oz.au>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!sibyl.eleceng.ua.oz.au!ianShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,2278f77e901502e2,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1990-05-30 21:39:20 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!shelby!apple!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!sibyl.eleceng.ua.oz.au!ian From: ian@sibyl.eleceng.ua.oz.au Newsgroups: gnu.gdb.bug Subject: Re: Variable array problems. Message-ID: <9006010109.1775@munnari.oz.au> Date: 31 May 90 04:39:20 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 50 Posted: Thu May 31 05:39:20 1990