I'm trying to use byaddr inside a template (I could use a macro as wel if need be) but it fails to compile - while the same code in a block works.
template test(x: string, body)=
var y {.byaddr, inject.} = x
body
var xx = "123"
test(xx):
echo y
Output
Error: invalid pragma: byaddr
I also tried defining & using byUnsafeAddr - which is a copy/paste definition of byaddr with unsafeaddr instead of addr.
template byUnsafeAddr(lhs, typ, expr) =
when typ is type(nil):
let tmp = unsafeAddr(expr)
else:
let tmp: ptr typ = unsafeAddr(expr)
template lhs: untyped = tmp[]
Same result.