Page 1 of 1

access a structured pointer like an array

Posted: Fri Dec 16, 2016 7:04 pm
by nco2k
this is something that has been bothering me for a long time now.

i really miss the possibility to access a structured pointer like an array:

Code: Select all

Protected *mem.struc

For i = 0 To 9
  Debug *mem[i]\bla
Next
same goes for strings:

Code: Select all

String$ = "ABC"

For i = 0 To 3
  Debug String$[i];\c
Next
i know there are dozen ways of how to achieve this, but it just isnt as small and sexy as the above code. :)

c ya,
nco2k

Re: access a structured pointer like an array

Posted: Fri Dec 16, 2016 8:18 pm
by Mistrel
I too miss the ability to arbitrarily walk the memory of a pointer as an array.

I know that you mentioned already knowing other ways to achieve this but I'll just drop the way I do it for others reading this thread who may not know a workaround:

Code: Select all

Structure SomeStruct
  a.i
  b.i
  c.i
EndStructure

Structure ArrayOfSomeStruct
  Offset.SomeStruct[0]
EndStructure

Define *Mem.ArrayOfSomeStruct=AllocateMemory(SizeOf(SomeStruct)*3)

*Mem\Offset[0]\a=1
*Mem\Offset[1]\b=2
*Mem\Offset[2]\c=3