| ... | @@ -536,7 +536,7 @@ const Timestamp = struct { | ... | @@ -536,7 +536,7 @@ const Timestamp = struct { |
| 536 | {#header_close#} | 536 | {#header_close#} |
| 537 | {#header_open|Top-Level Doc Comments#} | 537 | {#header_open|Top-Level Doc Comments#} |
| 538 | <p>User documentation that doesn't belong to whatever | 538 | <p>User documentation that doesn't belong to whatever |
| 539 | immediately follows it, like container-level documentation, goes | 539 | immediately follows it, like {#link|container|Containers#}-level documentation, goes |
| 540 | in top-level doc comments. A top-level doc comment is one that | 540 | in top-level doc comments. A top-level doc comment is one that |
| 541 | begins with two slashes and an exclamation point: | 541 | begins with two slashes and an exclamation point: |
| 542 | {#syntax#}//!{#endsyntax#}.</p> | 542 | {#syntax#}//!{#endsyntax#}.</p> |
| ... | @@ -1080,7 +1080,7 @@ fn addOne(number: i32) i32 { | ... | @@ -1080,7 +1080,7 @@ fn addOne(number: i32) i32 { |
| 1080 | <p> | 1080 | <p> |
| 1081 | When the <kbd>zig test</kbd> tool is building a test runner, only resolved {#syntax#}test{#endsyntax#} | 1081 | When the <kbd>zig test</kbd> tool is building a test runner, only resolved {#syntax#}test{#endsyntax#} |
| 1082 | declarations are included in the build. Initially, only the given Zig source file's top-level | 1082 | declarations are included in the build. Initially, only the given Zig source file's top-level |
| 1083 | declarations are resolved. Unless nested containers are referenced from a top-level test declaration, | 1083 | declarations are resolved. Unless nested {#link|containers|Containers#} are referenced from a top-level test declaration, |
| 1084 | nested container tests will not be resolved. | 1084 | nested container tests will not be resolved. |
| 1085 | </p> | 1085 | </p> |
| 1086 | <p> | 1086 | <p> |
| ... | @@ -1328,7 +1328,7 @@ const color: Color = .@"really red"; | ... | @@ -1328,7 +1328,7 @@ const color: Color = .@"really red"; |
| 1328 | | 1328 | |
| 1329 | {#header_open|Container Level Variables#} | 1329 | {#header_open|Container Level Variables#} |
| 1330 | <p> | 1330 | <p> |
| 1331 | Container level variables have static lifetime and are order-independent and lazily analyzed. | 1331 | {#link|Container|Containers#} level variables have static lifetime and are order-independent and lazily analyzed. |
| 1332 | The initialization value of container level variables is implicitly | 1332 | The initialization value of container level variables is implicitly |
| 1333 | {#link|comptime#}. If a container level variable is {#syntax#}const{#endsyntax#} then its value is | 1333 | {#link|comptime#}. If a container level variable is {#syntax#}const{#endsyntax#} then its value is |
| 1334 | {#syntax#}comptime{#endsyntax#}-known, otherwise it is runtime-known. | 1334 | {#syntax#}comptime{#endsyntax#}-known, otherwise it is runtime-known. |
| ... | @@ -1350,7 +1350,7 @@ const std = @import("std"); | ... | @@ -1350,7 +1350,7 @@ const std = @import("std"); |
| 1350 | const expect = std.testing.expect; | 1350 | const expect = std.testing.expect; |
| 1351 | {#code_end#} | 1351 | {#code_end#} |
| 1352 | <p> | 1352 | <p> |
| 1353 | Container level variables may be declared inside a {#link|struct#}, {#link|union#}, or {#link|enum#}: | 1353 | Container level variables may be declared inside a {#link|struct#}, {#link|union#}, {#link|enum#}, or {#link|opaque#}: |
| 1354 | </p> | 1354 | </p> |
| 1355 | {#code_begin|test|namespaced_container_level_variable#} | 1355 | {#code_begin|test|namespaced_container_level_variable#} |
| 1356 | const std = @import("std"); | 1356 | const std = @import("std"); |
| ... | @@ -7066,7 +7066,7 @@ test "fibonacci" { | ... | @@ -7066,7 +7066,7 @@ test "fibonacci" { |
| 7066 | {#code_end#} | 7066 | {#code_end#} |
| 7067 | | 7067 | |
| 7068 | <p> | 7068 | <p> |
| 7069 | At container level (outside of any function), all expressions are implicitly | 7069 | At {#link|container|Containers#} level (outside of any function), all expressions are implicitly |
| 7070 | {#syntax#}comptime{#endsyntax#} expressions. This means that we can use functions to | 7070 | {#syntax#}comptime{#endsyntax#} expressions. This means that we can use functions to |
| 7071 | initialize complex static data. For example: | 7071 | initialize complex static data. For example: |
| 7072 | </p> | 7072 | </p> |
| ... | @@ -7538,7 +7538,7 @@ volatile ( | ... | @@ -7538,7 +7538,7 @@ volatile ( |
| 7538 | | 7538 | |
| 7539 | {#header_open|Global Assembly#} | 7539 | {#header_open|Global Assembly#} |
| 7540 | <p> | 7540 | <p> |
| 7541 | When an assembly expression occurs in a container level {#link|comptime#} block, this is | 7541 | When an assembly expression occurs in a {#link|container|Containers#} level {#link|comptime#} block, this is |
| 7542 | <strong>global assembly</strong>. | 7542 | <strong>global assembly</strong>. |
| 7543 | </p> | 7543 | </p> |
| 7544 | <p> | 7544 | <p> |
| ... | @@ -8843,7 +8843,7 @@ fn func() void { | ... | @@ -8843,7 +8843,7 @@ fn func() void { |
| 8843 | {#header_open|@hasDecl#} | 8843 | {#header_open|@hasDecl#} |
| 8844 | <pre>{#syntax#}@hasDecl(comptime Container: type, comptime name: []const u8) bool{#endsyntax#}</pre> | 8844 | <pre>{#syntax#}@hasDecl(comptime Container: type, comptime name: []const u8) bool{#endsyntax#}</pre> |
| 8845 | <p> | 8845 | <p> |
| 8846 | Returns whether or not a {#link|struct#}, {#link|enum#}, or {#link|union#} has a declaration | 8846 | Returns whether or not a {#link|container|Containers#} has a declaration |
| 8847 | matching {#syntax#}name{#endsyntax#}. | 8847 | matching {#syntax#}name{#endsyntax#}. |
| 8848 | </p> | 8848 | </p> |
| 8849 | {#code_begin|test|hasDecl#} | 8849 | {#code_begin|test|hasDecl#} |
| ... | @@ -12436,6 +12436,19 @@ fn readU32Be() u32 {} | ... | @@ -12436,6 +12436,19 @@ fn readU32Be() u32 {} |
| 12436 | </div> | 12436 | </div> |
| 12437 | {#header_close#} | 12437 | {#header_close#} |
| 12438 | | 12438 | |
| | 12439 | {#header_open|Appendix#} |
| | 12440 | {#header_open|Containers#} |
| | 12441 | <p> |
| | 12442 | A <em>container</em> in Zig is any syntactical construct that acts as a namespace to hold {#link|variable|Container Level Variables#} and {#link|function|Functions#} declarations. |
| | 12443 | Containers are also type definitions which can be instantiated. |
| | 12444 | {#link|Structs|struct#}, {#link|enums|enum#}, {#link|unions|union#}, {#link|opaques|opaque#}, and even Zig source files themselves are containers. |
| | 12445 | </p> |
| | 12446 | <p> |
| | 12447 | Although containers (except Zig source files) use curly braces to surround their definition, they should not be confused with {#link|blocks|Blocks#} or functions. |
| | 12448 | Containers do not contain statements. |
| | 12449 | </p> |
| | 12450 | {#header_close#} |
| | 12451 | |
| 12439 | {#header_open|Grammar#} | 12452 | {#header_open|Grammar#} |
| 12440 | {#syntax_block|peg|grammar.y#}Root <- skip container_doc_comment? ContainerMembers eof | 12453 | {#syntax_block|peg|grammar.y#}Root <- skip container_doc_comment? ContainerMembers eof |
| 12441 | | 12454 | |
| ... | @@ -13001,6 +13014,7 @@ keyword <- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe | ... | @@ -13001,6 +13014,7 @@ keyword <- KEYWORD_align / KEYWORD_allowzero / KEYWORD_and / KEYWORD_anyframe |
| 13001 | <li>Together we serve the users.</li> | 13014 | <li>Together we serve the users.</li> |
| 13002 | </ul> | 13015 | </ul> |
| 13003 | {#header_close#} | 13016 | {#header_close#} |
| | 13017 | {#header_close#} |
| 13004 | </main></div> | 13018 | </main></div> |
| 13005 | </div> | 13019 | </div> |
| 13006 | </body> | 13020 | </body> |