Does anyone know an easy way to find the array bounds of an existing array? It would be like the Ubound and Lbound functions in VB.
tia
Array Bounds
Array Bounds
Missed it by that much!!
HK
HK
The following outputs the total number of entries.
Code: Select all
Dim a(12)
Debug PeekL(a()-8) ;Outputs 13 elements.
I may look like a mule, but I'm not a complete ass.
-
- Enthusiast
- Posts: 212
- Joined: Fri Apr 22, 2005 2:07 pm
- Location: U.S.A.
- Contact:
theres a simple structure before the array like in Linked lists
my guess it something like this
my guess it something like this
Code: Select all
Structure PB_Array
NumberOfElements.l
SizeOfElement.l
EndStructure
~Dreglor
-
- Enthusiast
- Posts: 212
- Joined: Fri Apr 22, 2005 2:07 pm
- Location: U.S.A.
- Contact:
That doesn't explain why PeekL(a()-8) returns the bounds of the array. Why does it work technically?
What does the code do?
DB
What does the code do?
DB
-- DB
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.
Albert Einstein
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.
Albert Einstein
a() simply returns the address of the array in memory (that is the array contents). I could have used @a() which I guess would make it more obvious.
Purebasic places some information pertinent to the array before the array itself. For example, at the location 8 bytes before the array contents (as referenced by a()-8 ), Purebasic makes a note of how many elements there are in the array.
The statement
thus returns the number of elements in the array.
Purebasic places some information pertinent to the array before the array itself. For example, at the location 8 bytes before the array contents (as referenced by a()-8 ), Purebasic makes a note of how many elements there are in the array.
The statement
Code: Select all
PeekL(a()-8)
I may look like a mule, but I'm not a complete ass.