Hello Charles
i had modified your ARRAY OF ARRAYS USING STRINGS program
and i can't figure out how your macro aa works?
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa int* (va,ix,iy)
@va=strptr sy(iy)+(ix)*4-4
end macro
especially the term (ix)*4-4
is this term an index to the array sy[ ] ?
is macro aa meant for 2 dimensional array so that the term (ix)*4-4
is an index pointer to the second dimension of the array sy[]
Here is a modification of your code :
'11:10 31/05/2018
'ARRAY OF ARRAYS USING STRINGS
$ filename "String_Array.exe"
uses rtl64
' http://www.oxygenbasic.org/forum/index.php?PHPSESSID=61ht1jfjq4f4854dmu41q84ov0&topic=1694.msg18411;topicseen#msg18411
'CREATE ARRAY FOR INTs
======================
string sy[100] 'STRING BUFFERS
int i
for i=1 to 100
sy[i]=nuls 50*sizeof int 'dim int sx[50]
sy[i] = i
next
'
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa int* (va,ix,iy)
@va=strptr sy(iy)+(ix)*4-4
end macro
'TESTS:
=======
aa(2,3)=42
aa(20,30)=100
print " aa(2,3)*aa(20,30) : " aa(2,3)*aa(20,30)
print " aa(1,1) : " aa(1,1)
print " aa(2,1) : " aa(2,1)
print " aa(3,1) : " aa(3,1)
Hi Chris,
The intent of this code was to show that arrays-of-arrays are possible, though not desirable if all you need is a regular 2d array.
The data buffer is an array of strings, and each string holds a row of data.
The macro function is used to access the array, assuming the elements are integers using indexbase 1 indexes.
I've changed the expression slightly to clarify how the address of va is calculated: va is the return variable.
macro aa int* (va,ix,iy)
@va=strptr(sy(iy)) +(ix)*4 -4
end macro
My code:
'ARRAY OF ARRAYS USING STRINGS
'CREATE ARRAY FOR INTs
======================
string sy[100] 'STRING BUFFERS
int i
for i=1 to 100
sy[i]=nuls 50*sizeof int 'dim int sx[50]
next
'
'ACCESS ARRAY (USING INDEXBASE 1)
=================================
macro aa int* (va,ix,iy)
@va=strptr(sy(iy)) +(ix)*4-4
end macro
'TESTS:
=======
aa(2,3)=42
aa(20,30)=100
print aa(2,3)*aa(20,30)
Thanxx Charles
could you please provide an example of a 2 D string array?