| ... | @@ -2588,7 +2588,7 @@ test "default struct initialization fields" { | ... | @@ -2588,7 +2588,7 @@ test "default struct initialization fields" { |
| 2588 | exactly their bit width. | 2588 | exactly their bit width. |
| 2589 | </li> | 2589 | </li> |
| 2590 | <li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li> | 2590 | <li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li> |
| 2591 | <li>A {#link|packed enum#} field uses exactly the bit width of its integer tag type.</li> | 2591 | <li>An {#link|enum#} field uses exactly the bit width of its integer tag type.</li> |
| 2592 | <li>A {#link|packed union#} field uses exactly the bit width of the union field with | 2592 | <li>A {#link|packed union#} field uses exactly the bit width of the union field with |
| 2593 | the largest bit width.</li> | 2593 | the largest bit width.</li> |
| 2594 | <li>Non-ABI-aligned fields are packed into the smallest possible | 2594 | <li>Non-ABI-aligned fields are packed into the smallest possible |
| ... | @@ -2983,25 +2983,6 @@ export fn entry(foo: Foo) void { } | ... | @@ -2983,25 +2983,6 @@ export fn entry(foo: Foo) void { } |
| 2983 | {#code_end#} | 2983 | {#code_end#} |
| 2984 | {#header_close#} | 2984 | {#header_close#} |
| 2985 | | 2985 | |
| 2986 | {#header_open|packed enum#} | | |
| 2987 | <p>By default, the size of enums is not guaranteed.</p> | | |
| 2988 | <p>{#syntax#}packed enum{#endsyntax#} causes the size of the enum to be the same as the size of the | | |
| 2989 | integer tag type of the enum:</p> | | |
| 2990 | {#code_begin|test#} | | |
| 2991 | const std = @import("std"); | | |
| 2992 | | | |
| 2993 | test "packed enum" { | | |
| 2994 | const Number = packed enum(u8) { | | |
| 2995 | one, | | |
| 2996 | two, | | |
| 2997 | three, | | |
| 2998 | }; | | |
| 2999 | std.testing.expect(@sizeOf(Number) == @sizeOf(u8)); | | |
| 3000 | } | | |
| 3001 | {#code_end#} | | |
| 3002 | <p>This makes the enum eligible to be in a {#link|packed struct#}.</p> | | |
| 3003 | {#header_close#} | | |
| 3004 | | | |
| 3005 | {#header_open|Enum Literals#} | 2986 | {#header_open|Enum Literals#} |
| 3006 | <p> | 2987 | <p> |
| 3007 | Enum literals allow specifying the name of an enum field without specifying the enum type: | 2988 | Enum literals allow specifying the name of an enum field without specifying the enum type: |