home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!munnari.oz.au!metro!mama!radics!zoltan
- From: zoltan@research.canon.oz.au (Zoltan Kocsi)
- Subject: Re: The 2-Dee Array Deelemna
- In-Reply-To: almeida@ame.gsfc.nasa.gov's message of Wed, 6 Jan 1993 19:03:55 GMT
- Message-ID: <ZOLTAN.93Jan11113115@radics.research.canon.oz.au>
- Originator: zoltan@radics
- Sender: news@research.canon.oz.au
- Organization: Canon Information Systems Research, Australia
- References: <1993Jan6.190355.9632@nsisrv.gsfc.nasa.gov>
- Date: Mon, 11 Jan 1993 01:31:15 GMT
- Lines: 45
-
- In article <1993Jan6.190355.9632@nsisrv.gsfc.nasa.gov> almeida@ame.gsfc.nasa.gov (aswin m. almeida) writes:
-
- [ text deleted ]
-
- for (i=0; i<10; i++)
- for (j=0; j<nrows; j++)
- {
- printf("%d x %d = %d\n",i,j,i*j);
- array[i][j] = i*j; /* dbx reports this as the location of the bus error */
- printf("%d,%d = %d\n",i,j,array[i][j]);
- [ text deleted ]
-
- 1) The reason I am getting this annoying bus error.
- 2) An explanation, with crude ASCII pictures, of *, **, and & in C.
- 3) An explanation of why | array[i] = (int *) malloc (ncolumns * sizeof(int));
-
- 1) The bus error is caused by wrong order of indices, your array
- ( with the given input ) is array[ 3 ][ 10 ] as you have an array that
- has nrows elements containing nculumns ints each.
-
- 2) and 3) In the memory it looks like this:
-
- --------------
- | array |--+ | |
- -------------- | -------------
- : : : |array[0][9]|
- -------------- | -------------
- | array[0] |<-+ : :
- --------------\ -------------
- | array[1] |-\------------>|array[1][0]|
- -------------- | -------------
- | array[2] |--+--+ |array[1][1]|
- -------------- | | -------------
- : : : | | |
- -------------- | | -------------
- | array[0][0]|<-+ | |array[1][9]|
- -------------- | -------------
- | array[0][1]| | : :
- -------------- | -------------
- | | +-------->|array[2][0]|
-
-
- Zoltan
- --
- Zoltan Kocsi <zoltan@research.canon.oz.au>
-