proc test( n_ref: ref int) =
echo n_ref
test(cast[ref int](addr 100)) #Is it too long?
Have implement quickly convert to ref? like it test(refaddr 100).Afaik this is wrong anyway. You can't simply cast something into a ref, as a ref is not just a pointer to the type. You also can not take the address of an int literal.
You could use a simple ptr here.
proc test( n_ptr: ptr int) =
echo n_ptr[]
var a: int = 100
test(a.addr)
But you maybe just want to do this:
proc test( n_var: var int) =
echo n_var # 100
inc n_var
var a: int = 100
test(a)
echo a # 101
Oh right, Thank you.
If It's object, Will be optimized(shallow copy or byref) when compile?
proc test( obj: MyObj) =
echo repr obj