Page 1 of 1
Static Array for Pointers
Posted: Sun Mar 07, 2021 2:03 pm
by Josh
If I have a memory area, either read in from a file or from the DataSection, that is constructed like an array, it would be fine to have an extension for pointers as exists within structures.
This would simplify the handling a lot and make the code more clear.
Re: Static Array for Pointers
Posted: Sun Mar 07, 2021 2:11 pm
by NicTheQuick
Are you aware of the workaround?
Code: Select all
Structure IntegerList
i.i[0]
EndStructure
Define *p.IntegerList
*p = ?mydata
Debug *p\i[0]
Debug *p\i[1]
Debug *p\i[2]
Debug *p\i[3]
Debug *p\i[4]
Debug *p\i[5]
DataSection
mydata:
Data.i 4, 6, 8, 2, 4, 12
EndDataSection
Re: Static Array for Pointers
Posted: Sun Mar 07, 2021 2:29 pm
by Josh
Of course I'm aware of that, but introducing an additional structure doesn't necessarily make the code better:
Code: Select all
Structure MYSTRUC
a.i
b.i
EndStructure
Structure MYSTRUCARRAY
MyStruc.MYSTRUC[0]
EndStructure
Define *p.MYSTRUCARRAY
*p = ?mydata
Debug *p\MyStruc[0]\a
Debug *p\MyStruc[0]\b
Debug *p\MyStruc[1]\a
Debug *p\MyStruc[1]\b
Debug *p\MyStruc[2]\a
Debug *p\MyStruc[2]\b
DataSection
mydata:
Data.i 4, 6, 8, 2, 4, 12
EndDataSection
Or simpler:
Code: Select all
Structure MYSTRUC
a.i
b.i
EndStructure
Define *p.MYSTRUC[0]
*p = ?mydata
Debug *p[0]\a
Debug *p[0]\b
Debug *p[1]\a
Debug *p[1]\b
Debug *p[2]\a
Debug *p[2]\b
DataSection
mydata:
Data.i 4, 6, 8, 2, 4, 12
EndDataSection
Re: Static Array for Pointers
Posted: Mon Mar 08, 2021 5:13 pm
by NicTheQuick
It would be nice to have this functionality like C has it. But what should we do in this case? Double indexed arrays?
Code: Select all
Structure myData
*list.i[2]
EndStructure
Define myData.myData
myData\list[0] = ?mydata0
myData\list[1] = ?mydata1
Debug myData\list[0][0] ;=4
Debug myData\list[0][1] ;=6
Debug myData\list[1][0] ;=5
;...
DataSection
mydata0:
Data.i 4, 6, 8, 2, 4, 12
mydata1:
Data.i 5, 7, 9, 3, 5, 13
EndDataSection
Re: Static Array for Pointers
Posted: Mon Mar 08, 2021 6:04 pm
by Mijikai
NicTheQuick wrote:...Double indexed arrays?
...
Yeah, it really sucks to use matrices with PB...
Re: Static Array for Pointers
Posted: Mon Mar 08, 2021 6:14 pm
by mk-soft
Only this way ...
Code: Select all
Structure ArrayOfInteger
iVal.i[0]
EndStructure
Structure myData
*list.ArrayOfInteger[3]
EndStructure
Define myData.myData
myData\list[0] = ?mydata0
myData\list[1] = ?mydata1
myData\list[2] = ?mydata2
Debug myData\list[0]\iVal[0] ;=4
Debug myData\list[0]\iVal[1] ;=6
Debug myData\list[1]\iVal[0] ;=5
Debug myData\list[2]\iVal[8] ;=116
;...
DataSection
mydata0:
Data.i 4, 6, 8, 2, 4, 12
mydata1:
Data.i 5, 7, 9, 3, 5, 13
mydata2:
Data.i 15, 17, 19, 13, 15, 113, 114, 115, 116
EndDataSection
or static column size
Code: Select all
Structure ArrayOfInteger
iVal.i[0]
EndStructure
Structure myDataColumn
col.i[6]
EndStructure
Structure myData
row.myDataColumn[0]
EndStructure
Define *myData.myData
*myData = ?mydata0
Debug *myData\row[0]\col[0] ;=4
Debug *myData\row[0]\col[1] ;=6
Debug *myData\row[1]\col[0] ;=5
Debug *myData\row[2]\col[5] ;=113
;...
DataSection
mydata0:
Data.i 4, 6, 8, 2, 4, 12
Data.i 5, 7, 9, 3, 5, 13
Data.i 15, 17, 19, 13, 15, 113
EndDataSection
Re: Static Array for Pointers
Posted: Mon Mar 08, 2021 9:42 pm
by Josh
I wasn't thinking so much about arrays with this post, certainly not multidimensional arrays. I was mainly concerned with the function as it is possible within structures with a static array [0].
With this you can organize so many things easily and clearly. For pointers this could be used well without the need for additional structures.
Especially for a look forward or backward, it has a special charm:
Code: Select all
Define *x.Character
x$ = "sdfs iotue rgdg" + #CRLF$ + "sdfsdf"
*x = @x$
For i = 1 To Len (x$)
If *x\c = #CR And *x[1]\c = #LF
Break
Wend
Next
P.S.: In my first post I didn't even think about the fact that the [0] in the 'Define' statement wouldn't be necessary at all.
Re: Static Array for Pointers
Posted: Tue Mar 09, 2021 9:57 am
by mk-soft
Code: Select all
Structure ArrayOfCharacater
c.c[0]
EndStructure
Define *x.ArrayOfCharacater
x$ = "sdfs iotue rgdg" + #CRLF$ + "sdfsdf"
*x = @x$
For i = 0 To Len(x$) - 1
If *x\c[i] = #CR And *x\c[i+1] = #LF
Debug "Break"
Break
EndIf
Next