Mail Archives: djgpp/1998/08/12/10:11:25
On 12 Aug 1998, Cephaler wrote:
> > Is map[x][y]->tile really an index? You didn't tell, but it could be
> > that map[x][y]->tile is already a pointer to the tile, so you don't
> > need to index tiles[] with it.
>
> Well, I know that tiles is perfectly fine, because I did some debugging
> code and dumped the tiles to the screen, and tile is an unsigned char..
That's not what I asked in the fragment you cite. I suggested that you
convince yourself that you really mean to do what your code says. Your
code uses tiles[j] where j is map[x][y]->tile. Usage such as tiles[j]
assumes that j is an integer whose value is between 0 and the last
element of the tiles[] array. If this assumptiopn is wrong, your program
will bomb.
Since your message didn't reveal your data structures, I could only guess
what might be wrong, and it is up to you to check which of the guesses
are right.
> > This will never work. You are using a pointer (an address of
> > map[x][y]->tile) as an index into an array.
>
> Hmmm is that supposed to be common knowledge?
Yes.
> Why not?
An index into an array must be a (relatively) small integer. If the array
has N elements, the index must be between 0 and N-1, or the program will
crash.
In contrast, an address of a variable is usually a large number (put
simplistically, it is the number of the byte where that variable is
stored), and could be anything. In particular, it can be much more than
N-1, which is the largest allowed index into an array.
> > It is usually a bad idea to use names with leading underscores.
>
> Not my fault, friend started graphics engine and left me to debug it...
I'm not your teacher, I'm not interested to know whose fault it is ;-).
I'm just telling you this, so you will know better in the future.
- Raw text -