-
Hello, why I have this error when I try to print the address memory of x? var x : Int = 42 # x must be mutable
let xPtr = Pointer[Int].address_of(x) # get address memory of x
print(xPtr.address_of()) # print address memory of x
print(xPtr.load()) # dereference the pointer and print value of x _error: Expression [9]:21:26: invalid call to 'address_of': callee expects 1 argument, but 0 were specified /.modular/Kernels/mojo/Stdlib/Pointer.mojo:103:5: function declared here |
Beta Was this translation helpful? Give feedback.
Answered by
DayDun
May 22, 2023
Replies: 1 comment 9 replies
-
If you want to print the address you probably want to write var x : Int = 42
let xPtr = Pointer[Int].address_of(x)
print(xPtr.__as_index())
print(xPtr.load())
|
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
survuvi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
address_of
is a static method and is not meant to be called on an instance, only on the type itself.If you want to print the address you probably want to write