New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign an array to sentinel array #16181
Comments
I agree. If the implicit conversion is somehow deemed controversial (not sure why), at least allowing it explicitly via Another alternative would be a dedicated |
Consider var array: [100_000]u8 = .{ 1, 2 };
var sentinel_array: [100_000:0]u8 = array;
which are not as helper functions smells like a bad design. Or do you have concrete code examples, where an inline function with comptime to create the zero-terminated memory structure[s] of a given array size is not possible? |
This is already the case for non-sentinel copies of arrays. This would be an argument against status quo as well. |
Or do you have a brief counter-example? Not a fan, but consistent. Reason why I dislike the current behavior: test {
var x: u8 = 100;
var a: [1_000]u8 = .{x} ** 1_000;
var b: [1_000]u8 = undefined;
// a pile of code
b = a; // spot the performance issue
// a pile of code
} |
I mean... just try it? You can totally copy arrays, they're nothing special: test {
var x: u8 = 100;
var a: [1000]u8 = .{x} ** 1000;
var b: [1000]u8 = a;
_ = b;
}
|
I think array copies should be explicit anyway.
code on compiler explorer fun:
push rax
mov edi, offset example.a
mov edx, 1000
mov esi, 100
call memset@PLT
mov edi, offset example.b
mov edx, 1000
mov esi, 100
call memset@PLT
mov edi, offset example.a
mov esi, offset example.b
pop rax
jmp f@PLT |
Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
error: expected type '[2:0]u8', found '[2]u8'
Expected Behavior
There is no reason to prohibit this operation. That is just a copy.
The text was updated successfully, but these errors were encountered: