const std = @import("std");
fn rvo() []usize {
var a = [_]usize{ 1, 2, 3 };
return &a;
}
pub fn main() !void {
const a = rvo();
const b = rvo();
std.debug.print("{any}\n{any}", .{ a, b });
}
I'm a bit confused with this; the output is:
{ 12391456, 587280153432, 587280153432 }
{ 12391456, 587280153432, 587280153432 }
In most languages I feel like this is either copied to the call-site stack frame or initially allocated on the call-site using RVO. In zig I get neither and I've run into this issue many times. If I want to do something as simple as a function call and I want to return an array from that function without allocating what should I do? ๐ thanks a lot in advance!