A89: Re: Arrays


[Prev][Next][Index][Thread]

A89: Re: Arrays




I don't understand what you are saying exactly, but for what it's worth,
shorts are defined by the ANSI standard to be 16 bits. Also, pointer
arithmetic is automatic in a sense - you shouldn't need to use sizeof for
that. Example:

short a[25];
int i;
for (i=0; i<25; i++)
{
    a[i] = i;
}

printf("%d %d %d", a[3], *(a+3), *(a+4));

This should print "3 3 4". The compiler interprets the addition of a pointer
p and an integer i as

p + sizeof(*p) * i

but it would be wrong to use this in the actual source.

-Kevin


-----Original Message-----
From: B Clark <nix249@mich.com>
To: assembly-89@lists.ticalc.org <assembly-89@lists.ticalc.org>
Date: Sunday, December 31, 2000 12:23 PM
Subject: A89: Arrays


>
>I was trying to use pointer arithmetic in my current program, in order to
>find the different parts of an array holding a sprite.  The array is made
up
>of unsigned shorts, so I used sizeof(unsigned short)*TILE_HEIGHT, where
>TILE_HEIGHT is the number of elements in that part of the array, to find
the
>size. However, the sprite wouldn't display correctly. Using sprintf, I
found
>this to be 32 bytes. However, when I subtracted the address of the array
>parts, it was shown as 16 bytes.  The sprites will only be displayed right
>if I add 16 bytes to the base address, so I believe this to be right. Why
>isn't this 32 bytes?
>
>




Follow-Ups: