access a structured pointer like an array

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

access a structured pointer like an array

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: access a structured pointer like an array

Post 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
Post Reply