
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses




Task

Demonstrate how to get the address of a variable and how to set the address of a variable.




 
' Adapted from QB64wiki example a demo of _MEM type data and _MEM functions
Type points
    x As Integer
    y As Integer
    z As Integer
End Type
 
Dim Shared m(3) As _MEM
Dim Shared Saved As points, first As points
 
m(1) = _Mem(first.x)
m(2) = _Mem(first.y)
m(3) = _Mem(first.z)
 
print "QB64 way to manage address of variable..."
first.x = 3: first.y = 5: first.z = 8
Print first.x, first.y, first.z
Save first
first.x = 30: first.y = 50: first.z = 80
Print first.x, first.y, first.z
 
RestoreIt
Print first.x, first.y, first.z
 
_MemFree m(1)
_MemFree m(2)
_MemFree m(3)
End
 
Sub Save (F As points)
    Saved.x = F.x
    Saved.y = F.y
    Saved.z = F.z
End Sub
 
Sub RestoreIt
    _MemPut m(1), m(1).OFFSET, Saved.x
    _MemPut m(2), m(2).OFFSET, Saved.y
    _MemPut m(3), m(3).OFFSET, Saved.z
End Sub
 