by ward@[EMAIL PROTECTED]
(ward mcfarland)
Jan 22, 2005 at 06:33 AM
jd <jeandal34@[EMAIL PROTECTED]
> wrote:
> Hi,
>
> I am running MacForth 5.2 on a Mac and have very strange things
> happening with my arrays. When i create an array and enter a value in
> the first cell as follows:
> create MyArray 12 allot
> 221 MyArray !
221 == hex 000000DD
This stores DD in MyArray + 3 (3 = byte offset)
>
> if i view the content of the first cell the value is right:
> MyArray @[EMAIL PROTECTED]
.
> 221
>
> However if i now enter a value in the second cell of the 16 bit array:
> 230 MyArray 2 + !
This stores hex 000000E6 in
MyArray + 2 (2 = byte offset)
+DUMP can be your friend here to see what is being stored where.
For 4 bytes per array element, you need to do
create MyArray 12 4 * allot ( to make an array of 12 longs)
or
create MyArray 12 CELLS allot
and access as:
230 MyArray 2 4 * + !
or
230 MyArray 2 cells + !
If you want a simpler style, use MacForth's 1ARRAY word as follows:
12 4 1ARRAY MyArray
Then
221 0 Myarray !
230 1 MyArray !
0 MyArray @[EMAIL PROTECTED]
.
221
1 MyArray @[EMAIL PROTECTED]
.
230
Now, if you wanted only 1 BYTE per element originally, then you should
have used C@[EMAIL PROTECTED]
and C! to access the elements.
-- ward