Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1 +1,4 @@
|
|||
{{basic data operation}}Demonstrate how to get the address of a variable and how to set the address of a variable.
|
||||
{{basic data operation}}
|
||||
|
||||
Demonstrate how to get the address of a variable
|
||||
and how to set the address of a variable.
|
||||
|
|
|
|||
|
|
@ -1,16 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func main() {
|
||||
myVar := 3.14
|
||||
myPointer := &myVar
|
||||
fmt.Println(myPointer)
|
||||
fmt.Printf("%p\n", myPointer)
|
||||
myVar := 3.14
|
||||
myPointer := &myVar
|
||||
fmt.Println("Address:", myPointer, &myVar)
|
||||
fmt.Printf("Address: %p %p\n", myPointer, &myVar)
|
||||
|
||||
addr := int64(uintptr(unsafe.Pointer(myPointer)))
|
||||
fmt.Printf("0x%x\n", addr)
|
||||
var addr64 int64
|
||||
var addr32 int32
|
||||
ptr := unsafe.Pointer(myPointer)
|
||||
if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr64) {
|
||||
addr64 = int64(uintptr(ptr))
|
||||
fmt.Printf("Pointer stored in int64: %#016x\n", addr64)
|
||||
}
|
||||
if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr32) {
|
||||
// Only runs on architectures where a pointer is <= 32 bits
|
||||
addr32 = int32(uintptr(ptr))
|
||||
fmt.Printf("Pointer stored in int32: %#08x\n", addr32)
|
||||
}
|
||||
addr := uintptr(ptr)
|
||||
fmt.Printf("Pointer stored in uintptr: %#08x\n", addr)
|
||||
|
||||
fmt.Println("value as float:", myVar)
|
||||
i := (*int32)(unsafe.Pointer(&myVar))
|
||||
fmt.Printf("value as int32: %#08x\n", *i)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
zzz=storage(xxx)
|
||||
zzz = storage(xxx)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
Dim TheAddress as long
|
||||
Dim SecVar as byte
|
||||
Dim MyVar as byte
|
||||
MyVar = 10
|
||||
|
||||
'Get the address of MyVar
|
||||
TheAddress = varptr(MyVar)
|
||||
|
||||
'Set a new value on the address
|
||||
MEMSET(TheAddress, 102, SizeOf(byte))
|
||||
|
||||
'Myvar is now = 102
|
||||
showmessage "MyVar = " + str$(MyVar)
|
||||
|
||||
'...or copy from one address to another using:
|
||||
MEMCPY(VarPtr(SecVar), TheAddress, SizeOf(byte))
|
||||
|
||||
'SecVar is now also = 102
|
||||
showmessage "SecVar = " + str$(SecVar)
|
||||
Loading…
Add table
Add a link
Reference in a new issue