Reputation: 23537
In Rust, you can use the black_box
function to force the compiler to
Is there a similar facility in Go (to accomplish either task)?
Upvotes: 0
Views: 547
Reputation: 42433
Is there a similar facility in Go (to accomplish either task)?
No.
If you want to use a result: Assign to an exported global.
Upvotes: 2
Reputation: 60117
I believe runtime.KeepAlive
is recommended, as per the following Github issue. Unfortunately, it's unclear whether anything exists for function arguments, or whether KeepAlive
is even guaranteed to work.
https://github.com/golang/go/issues/27400
Upvotes: 1