OffsetOf() to support array elements

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

OffsetOf() to support array elements

Post by Mistrel »

I have a particular structure where I want to know the offset of certain fields:

Code: Select all

Structure SomeStruct
  a1.l
  a2.l
  a3.l
  b1.l
  b2.l
  b3.l
  c1.l
  c2.l
  c3.l
EndStructure
This works OK for OffsetOf() as it is. But these fields are similar enough to be in an array, which doesn't support OffsetOf():

Code: Select all

Structure SomeStruct
  a.l[3]
  b.l[3]
  c.l[3]
EndStructure
It would be nice if we could do this:

Code: Select all

OffsetOf(SomeStruct\b[2])
Instead of card-coding this:

Code: Select all

OffsetOf(SomeStruct\b)+SizeOf(Long)*2
You might think that you could use SizeOf() on the field but this returns the size of the entire array.