RosettaCodeData/Task/Address-of-a-variable/PowerBASIC/address-of-a-variable.basic
2023-07-01 13:44:08 -04:00

18 lines
495 B
Text

'get a variable's address:
DIM x AS INTEGER, y AS LONG
y = VARPTR(x)
'can't set the address of a single variable, but can access memory locations
DIM z AS INTEGER
z = PEEK(INTEGER, y)
'or can do it one byte at a time
DIM zz(1) AS BYTE
zz(0) = PEEK(BYTE, y)
zz(1) = PEEK(BYTE, y + 1)
'(MAK creates an INTEGER, LONG, or QUAD out of the next smaller type)
z = MAK(INTEGER, zz(0), zz(1))
'*can* set the address of an array
DIM zzz(1) AS BYTE AT y
'zzz(0) = low byte of x, zzz(1) = high byte of x