diff --git a/doc/langref.html.in b/doc/langref.html.in index 627709ec84..b0003a714b 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -1734,6 +1734,43 @@ test "array initialization with function calls" { {#code_end#} {#see_also|for|Slices#} + {#header_open|Anonymous List Literals#} +

Similar to {#link|Enum Literals#} and {#link|Anonymous Struct Literals#} + the type can be omitted from array literals:

+ {#code_begin|test|anon_list#} +const std = @import("std"); +const assert = std.debug.assert; + +test "anonymous list literal syntax" { + var array: [4]u8 = .{11, 22, 33, 44}; + assert(array[0] == 11); + assert(array[1] == 22); + assert(array[2] == 33); + assert(array[3] == 44); +} + {#code_end#} +

+ If there is no type in the result location then an anonymous list literal actually + turns into a {#link|struct#} with numbered field names: +

+ {#code_begin|test|infer_list_literal#} +const std = @import("std"); +const assert = std.debug.assert; + +test "fully anonymous list literal" { + dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"}); +} + +fn dump(args: var) void { + assert(args.@"0" == 1234); + assert(args.@"1" == 12.34); + assert(args.@"2"); + assert(args.@"3"[0] == 'h'); + assert(args.@"3"[1] == 'i'); +} + {#code_end#} + {#header_close#} + {#header_open|Multidimensional Arrays#}

Mutlidimensional arrays can be created by nesting arrays: @@ -2526,7 +2563,8 @@ test "overaligned pointer to packed struct" { Don't worry, there will be a good solution for this use case in zig.

{#header_close#} - {#header_open|struct Naming#} + + {#header_open|Struct Naming#}

Since all structs are anonymous, Zig infers the type name based on a few rules.