Referencing variables via pointers
#1
A little proof of concept method for a bigger program that I'm playing around with, which allows us to reference variables by offset rather than by name.

Code: (Select All)
Dim foo As Integer
Dim foo2 As _Unsigned _Byte
Dim foo3 As Long

Print foo, foo2, foo3

ToggleVar _Offset(foo), Len(foo)
ToggleVar _Offset(foo2), Len(foo2)
ToggleVar _Offset(foo3), Len(foo3)

Print foo, foo2, foo3

ToggleVar _Offset(foo), Len(foo)
ToggleVar _Offset(foo2), Len(foo2)
ToggleVar _Offset(foo3), Len(foo3)

Print foo, foo2, foo3

Sub ToggleVar (variable_offset As _Offset, variable_size As _Byte)
    Static m As _MEM
    m = _Mem(variable_offset, variable_size)
    Select Case variable_size
        Case 1
            temp%% = _MemGet(m, m.OFFSET, _Byte)
            _MemPut m, m.OFFSET, Not temp%% As _BYTE
        Case 2
            temp% = _MemGet(m, m.OFFSET, Integer)
            _MemPut m, m.OFFSET, Not temp% As INTEGER
        Case 4
            temp& = _MemGet(m, m.OFFSET, Long)
            _MemPut m, m.OFFSET, Not temp& As LONG
        Case 8
            temp&& = _MemGet(m, m.OFFSET, _Integer64)
            _MemPut m, m.OFFSET, Not temp&& As _INTEGER64
    End Select
End Sub

Take a moment and be certain to notice that these are 3 different type variables all being processed and altered via the same SUB. Smile
Reply


Messages In This Thread
Referencing variables via pointers - by SMcNeill - 10-21-2022, 03:49 PM
RE: Referencing variables via pointers - by Pete - 10-21-2022, 03:58 PM
RE: Referencing variables via pointers - by Pete - 10-22-2022, 01:25 AM
RE: Referencing variables via pointers - by Pete - 10-23-2022, 03:03 PM



Users browsing this thread: 6 Guest(s)