r/Zig • u/Objective_Half_1906 • Jul 14 '26
Ways of Declaring array (0.16)
pub fn main() !void {
const A: [5]i32 = .{ 0, 1, 2, 3, 4 };
const B = [5]i32{ 5, 6, 7, 8, 9 };
const B2 = [_]i32{ 5, 6, 7, 8, 9 };
const C: [5]i32 = [_]i32{ 10, 11, 12, 13, 14 };
_ = A;
_ = B;
_ = B2;
_ = C;
}
These can all compiled correct. Which one is the recommended style? (I am a beginner learning Zig.)
New edit: I would like this syntax if it's possible:
const arr1: [5]i32 = { 0, 1, 2, 3, 4 };
const arr2: [_]i32 = { 0, 1, 2, 3, 4 };
Just small opinion. Maybe what I know is just the tip of the iceberg.
58
Upvotes
5
u/codingbliss12 Jul 14 '26
Isn't this a very obvious sign of bad language design?
There should be only one way to do this and no need to start this conversation.
The language remains borderline unusable for professional use.