| ... | ... | @@ -923,21 +923,21 @@ fn foo() i32 { |
| 923 | 923 | It is also possible to have local variables with static lifetime by using containers inside functions. |
| 924 | 924 | </p> |
| 925 | 925 | {#code_begin|test|static_local_variable#} |
| 926 | | const std = @import("std"); |
| 927 | | const expect = std.testing.expect; |
| 928 | | |
| 929 | | test "static local variable" { |
| 930 | | try expect(foo() == 1235); |
| 931 | | try expect(foo() == 1236); |
| 932 | | } |
| 933 | | |
| 934 | | fn foo() i32 { |
| 935 | | const S = struct { |
| 936 | | var x: i32 = 1234; |
| 937 | | }; |
| 938 | | S.x += 1; |
| 939 | | return S.x; |
| 940 | | } |
| 926 | const std = @import("std"); |
| 927 | const expect = std.testing.expect; |
| 928 | |
| 929 | test "static local variable" { |
| 930 | try expect(foo() == 1235); |
| 931 | try expect(foo() == 1236); |
| 932 | } |
| 933 | |
| 934 | fn foo() i32 { |
| 935 | const S = struct { |
| 936 | var x: i32 = 1234; |
| 937 | }; |
| 938 | S.x += 1; |
| 939 | return S.x; |
| 940 | } |
| 941 | 941 | {#code_end#} |
| 942 | 942 | <p> |
| 943 | 943 | The {#syntax#}extern{#endsyntax#} keyword or {#link|@extern#} builtin function can be used to link against a variable that is exported |