-
I couldn't find any good examples on how to use the from memory.unsafe import Pointer
@value
@register_passable("trivial")
struct Pair:
var a: Int
#var b: Pointer[Int]
def main():
var ex_a = 5
#var ex_b = Pointer[Int]()
#ex_b[0] = 5
var ex_pair = Pair(ex_a)#, ex_b)
print(ex_pair.a)
#print(ex_pair.b)
print("Worked?") |
Beta Was this translation helpful? Give feedback.
Answered by
Moosems
Mar 31, 2024
Replies: 1 comment
-
I got it working: from memory.unsafe import Pointer
@value
@register_passable("trivial")
struct Pair:
var a: Int
var b: Pointer[Int]
def main():
var ex_a = 5
var ex_b = Pointer[Int].alloc(1)
ex_b[0] = 5
var ex_pair = Pair(ex_a, ex_b)
print(ex_pair.a)
print(ex_pair.b.load())
print("Worked?") |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Moosems
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got it working: