authorgravatar for scheibo@users.noreply.github.comKirk Scheibelhut <scheibo@users.noreply.github.com> 2022-02-04 11:27:50-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-02-07 12:22:06-07:00
log3c40cf1693df735c5d06ce98fce48532df2a3f22
tree1ba2186cdbd1e5526fe20bfc5fcddbe09c51c592
parent5cfc22bd36d1b34611a65ea59815bb83bdc248e6

Various documentation fixes

Co-authored-by: Kirk Scheibelhut <kjs@scheibo.com> Co-authored-by: extrasharp <genericpb@gmail.com>

1 files changed, 111 insertions(+), 63 deletions(-)

doc/langref.html.in+111-63
...@@ -1290,13 +1290,39 @@ test "expectError demo" {...@@ -1290,13 +1290,39 @@ test "expectError demo" {
1290 A variable is a unit of {#link|Memory#} storage.1290 A variable is a unit of {#link|Memory#} storage.
1291 </p>1291 </p>
1292 <p>1292 <p>
1293 Variables are never allowed to shadow identifiers from an outer scope.
1294 </p>
1295 <p>
1296 It is generally preferable to use {#syntax#}const{#endsyntax#} rather than1293 It is generally preferable to use {#syntax#}const{#endsyntax#} rather than
1297 {#syntax#}var{#endsyntax#} when declaring a variable. This causes less work for both1294 {#syntax#}var{#endsyntax#} when declaring a variable. This causes less work for both
1298 humans and computers to do when reading code, and creates more optimization opportunities.1295 humans and computers to do when reading code, and creates more optimization opportunities.
1299 </p>1296 </p>
1297
1298 {#header_open|Identifiers#}
1299 <p>
1300 Variable identifiers are never allowed to shadow identifiers from an outer scope.
1301 </p>
1302 <p>
1303 Identifiers must start with an alphabetic character or underscore and may be followed
1304 by any number of alphanumeric characters or underscores.
1305 They must not overlap with any keywords. See {#link|Keyword Reference#}.
1306 </p>
1307 <p>
1308 If a name that does not fit these requirements is needed, such as for linking with external libraries, the {#syntax#}@""{#endsyntax#} syntax may be used.
1309 </p>
1310 {#code_begin|syntax#}
1311const @"identifier with spaces in it" = 0xff;
1312const @"1SmallStep4Man" = 112358;
1313
1314const c = @import("std").c;
1315pub extern "c" fn @"error"() anyopaque;
1316pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;
1317
1318const Color = enum {
1319 red,
1320 @"really red",
1321};
1322const color: Color = .@"really red";
1323 {#code_end#}
1324 {#header_close#}
1325
1300 {#header_open|Container Level Variables#}1326 {#header_open|Container Level Variables#}
1301 <p>1327 <p>
1302 Container level variables have static lifetime and are order-independent and lazily analyzed.1328 Container level variables have static lifetime and are order-independent and lazily analyzed.
...@@ -1481,7 +1507,7 @@ fn divide(a: i32, b: i32) i32 {...@@ -1481,7 +1507,7 @@ fn divide(a: i32, b: i32) i32 {
1481 </p>1507 </p>
1482 <p>1508 <p>
1483 Operators such as {#syntax#}+{#endsyntax#} and {#syntax#}-{#endsyntax#} cause undefined behavior on1509 Operators such as {#syntax#}+{#endsyntax#} and {#syntax#}-{#endsyntax#} cause undefined behavior on
1484 integer overflow. Alternative operators are provided for wrapping and saturating arithmetic on all targets. 1510 integer overflow. Alternative operators are provided for wrapping and saturating arithmetic on all targets.
1485 {#syntax#}+%{#endsyntax#} and {#syntax#}-%{#endsyntax#} perform wrapping arithmetic1511 {#syntax#}+%{#endsyntax#} and {#syntax#}-%{#endsyntax#} perform wrapping arithmetic
1486 while {#syntax#}+|{#endsyntax#} and {#syntax#}-|{#endsyntax#} perform saturating arithmetic.1512 while {#syntax#}+|{#endsyntax#} and {#syntax#}-|{#endsyntax#} perform saturating arithmetic.
1487 </p>1513 </p>
...@@ -2488,32 +2514,32 @@ test "null terminated array" {...@@ -2488,32 +2514,32 @@ test "null terminated array" {
2488 or using the shorthand function {#syntax#}std.meta.Vector{#endsyntax#}.2514 or using the shorthand function {#syntax#}std.meta.Vector{#endsyntax#}.
2489 </p>2515 </p>
2490 <p>2516 <p>
2491 Vectors support the same builtin operators as their underlying base types. These operations are performed 2517 Vectors support the same builtin operators as their underlying base types. These operations are performed
2492 element-wise, and return a vector of the same length as the input vectors. This includes:2518 element-wise, and return a vector of the same length as the input vectors. This includes:
2493 </p>2519 </p>
2494 <ul>2520 <ul>
2495 <li>Arithmetic ({#syntax#}+{#endsyntax#}, {#syntax#}-{#endsyntax#}, {#syntax#}/{#endsyntax#}, {#syntax#}*{#endsyntax#}, 2521 <li>Arithmetic ({#syntax#}+{#endsyntax#}, {#syntax#}-{#endsyntax#}, {#syntax#}/{#endsyntax#}, {#syntax#}*{#endsyntax#},
2496 {#syntax#}@divFloor{#endsyntax#}, {#syntax#}@sqrt{#endsyntax#}, {#syntax#}@ceil{#endsyntax#}, 2522 {#syntax#}@divFloor{#endsyntax#}, {#syntax#}@sqrt{#endsyntax#}, {#syntax#}@ceil{#endsyntax#},
2497 {#syntax#}@log{#endsyntax#}, etc.)</li>2523 {#syntax#}@log{#endsyntax#}, etc.)</li>
2498 <li>Bitwise operators ({#syntax#}>>{#endsyntax#}, {#syntax#}<<{#endsyntax#}, {#syntax#}&{#endsyntax#}, 2524 <li>Bitwise operators ({#syntax#}>>{#endsyntax#}, {#syntax#}<<{#endsyntax#}, {#syntax#}&{#endsyntax#},
2499 {#syntax#}|{#endsyntax#}, {#syntax#}~{#endsyntax#}, etc.)</li>2525 {#syntax#}|{#endsyntax#}, {#syntax#}~{#endsyntax#}, etc.)</li>
2500 <li>Comparison operators ({#syntax#}<{#endsyntax#}, {#syntax#}>{#endsyntax#}, {#syntax#}=={#endsyntax#}, etc.)</li>2526 <li>Comparison operators ({#syntax#}<{#endsyntax#}, {#syntax#}>{#endsyntax#}, {#syntax#}=={#endsyntax#}, etc.)</li>
2501 </ul>2527 </ul>
2502 <p>2528 <p>
2503 It is prohibited to use a math operator on a mixture of scalars (individual numbers) and vectors. 2529 It is prohibited to use a math operator on a mixture of scalars (individual numbers) and vectors.
2504 Zig provides the {#link|@splat#} builtin to easily convert from scalars to vectors, and it supports {#link|@reduce#} 2530 Zig provides the {#link|@splat#} builtin to easily convert from scalars to vectors, and it supports {#link|@reduce#}
2505 and array indexing syntax to convert from vectors to scalars. Vectors also support assignment to and from 2531 and array indexing syntax to convert from vectors to scalars. Vectors also support assignment to and from
2506 fixed-length arrays with comptime known length.2532 fixed-length arrays with comptime known length.
2507 </p>2533 </p>
2508 <p>2534 <p>
2509 For rearranging elements within and between vectors, Zig provides the {#link|@shuffle#} and {#link|@select#} functions.2535 For rearranging elements within and between vectors, Zig provides the {#link|@shuffle#} and {#link|@select#} functions.
2510 </p>2536 </p>
2511 <p>2537 <p>
2512 Operations on vectors shorter than the target machine's native SIMD size will typically compile to single SIMD 2538 Operations on vectors shorter than the target machine's native SIMD size will typically compile to single SIMD
2513 instructions, while vectors longer than the target machine's native SIMD size will compile to multiple SIMD 2539 instructions, while vectors longer than the target machine's native SIMD size will compile to multiple SIMD
2514 instructions. If a given operation doesn't have SIMD support on the target architecture, the compiler will default 2540 instructions. If a given operation doesn't have SIMD support on the target architecture, the compiler will default
2515 to operating on each vector element one at a time. Zig supports any comptime-known vector length up to 2^32-1, 2541 to operating on each vector element one at a time. Zig supports any comptime-known vector length up to 2^32-1,
2516 although small powers of two (2-64) are most typical. Note that excessively long vector lengths (e.g. 2^20) may 2542 although small powers of two (2-64) are most typical. Note that excessively long vector lengths (e.g. 2^20) may
2517 result in compiler crashes on current versions of Zig.2543 result in compiler crashes on current versions of Zig.
2518 </p>2544 </p>
2519 {#code_begin|test|vector_example#}2545 {#code_begin|test|vector_example#}
...@@ -2563,7 +2589,7 @@ test "Conversion between vectors, arrays, and slices" {...@@ -2563,7 +2589,7 @@ test "Conversion between vectors, arrays, and slices" {
2563 TODO consider suggesting std.MultiArrayList2589 TODO consider suggesting std.MultiArrayList
2564 </p>2590 </p>
2565 {#see_also|@splat|@shuffle|@select|@reduce#}2591 {#see_also|@splat|@shuffle|@select|@reduce#}
2566 2592
2567 {#header_close#}2593 {#header_close#}
25682594
2569 {#header_open|Pointers#}2595 {#header_open|Pointers#}
...@@ -2981,8 +3007,8 @@ test "null terminated slice" {...@@ -2981,8 +3007,8 @@ test "null terminated slice" {
2981}3007}
2982 {#code_end#}3008 {#code_end#}
2983 <p>3009 <p>
2984 Sentinel-terminated slices can also be created using a variation of the slice syntax 3010 Sentinel-terminated slices can also be created using a variation of the slice syntax
2985 {#syntax#}data[start..end :x]{#endsyntax#}, where {#syntax#}data{#endsyntax#} is a many-item pointer, 3011 {#syntax#}data[start..end :x]{#endsyntax#}, where {#syntax#}data{#endsyntax#} is a many-item pointer,
2986 array or slice and {#syntax#}x{#endsyntax#} is the sentinel value.3012 array or slice and {#syntax#}x{#endsyntax#} is the sentinel value.
2987 </p>3013 </p>
2988 {#code_begin|test|null_terminated_slicing#}3014 {#code_begin|test|null_terminated_slicing#}
...@@ -2999,7 +3025,7 @@ test "null terminated slicing" {...@@ -2999,7 +3025,7 @@ test "null terminated slicing" {
2999}3025}
3000 {#code_end#}3026 {#code_end#}
3001 <p>3027 <p>
3002 Sentinel-terminated slicing asserts that the element in the sentinel position of the backing data is 3028 Sentinel-terminated slicing asserts that the element in the sentinel position of the backing data is
3003 actually the sentinel value. If this is not the case, safety-protected {#link|Undefined Behavior#} results.3029 actually the sentinel value. If this is not the case, safety-protected {#link|Undefined Behavior#} results.
3004 </p>3030 </p>
3005 {#code_begin|test_safety|sentinel mismatch#}3031 {#code_begin|test_safety|sentinel mismatch#}
...@@ -3008,10 +3034,10 @@ const expect = std.testing.expect;...@@ -3008,10 +3034,10 @@ const expect = std.testing.expect;
30083034
3009test "sentinel mismatch" {3035test "sentinel mismatch" {
3010 var array = [_]u8{ 3, 2, 1, 0 };3036 var array = [_]u8{ 3, 2, 1, 0 };
3011 3037
3012 // Creating a sentinel-terminated slice from the array with a length of 2 3038 // Creating a sentinel-terminated slice from the array with a length of 2
3013 // will result in the value `1` occupying the sentinel element position. 3039 // will result in the value `1` occupying the sentinel element position.
3014 // This does not match the indicated sentinel value of `0` and will lead 3040 // This does not match the indicated sentinel value of `0` and will lead
3015 // to a runtime panic.3041 // to a runtime panic.
3016 var runtime_length: usize = 2;3042 var runtime_length: usize = 2;
3017 const slice = array[0..runtime_length :0];3043 const slice = array[0..runtime_length :0];
...@@ -3159,7 +3185,7 @@ test "linked list" {...@@ -3159,7 +3185,7 @@ test "linked list" {
3159 .last = &node,3185 .last = &node,
3160 .len = 1,3186 .len = 1,
3161 };3187 };
3162 3188
3163 // When using a pointer to a struct, fields can be accessed directly,3189 // When using a pointer to a struct, fields can be accessed directly,
3164 // without explicitly dereferencing the pointer.3190 // without explicitly dereferencing the pointer.
3165 // So you can do3191 // So you can do
...@@ -3491,7 +3517,7 @@ fn dump(args: anytype) !void {...@@ -3491,7 +3517,7 @@ fn dump(args: anytype) !void {
3491 </p>3517 </p>
3492 <p>3518 <p>
3493 The fields are implicitly named using numbers starting from 0. Because their names are integers,3519 The fields are implicitly named using numbers starting from 0. Because their names are integers,
3494 the {#syntax#}@"0"{#endsyntax#} syntax must be used to access them. Names inside {#syntax#}@""{#endsyntax#} are always recognised as identifiers.3520 the {#syntax#}@"0"{#endsyntax#} syntax must be used to access them. Names inside {#syntax#}@""{#endsyntax#} are always recognised as {#link|identifiers|Identifiers#}.
3495 </p>3521 </p>
3496 <p>3522 <p>
3497 Like arrays, tuples have a .len field, can be indexed and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}.3523 Like arrays, tuples have a .len field, can be indexed and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}.
...@@ -3980,7 +4006,7 @@ test "labeled break from labeled block expression" {...@@ -3980,7 +4006,7 @@ test "labeled break from labeled block expression" {
3980 {#see_also|Labeled while|Labeled for#}4006 {#see_also|Labeled while|Labeled for#}
39814007
3982 {#header_open|Shadowing#}4008 {#header_open|Shadowing#}
3983 <p>Identifiers are never allowed to "hide" other identifiers by using the same name:</p>4009 <p>{#link|Identifiers#} are never allowed to "hide" other identifiers by using the same name:</p>
3984 {#code_begin|test_err|local shadows declaration#}4010 {#code_begin|test_err|local shadows declaration#}
3985const pi = 3.14;4011const pi = 3.14;
39864012
...@@ -3992,8 +4018,8 @@ test "inside test block" {...@@ -3992,8 +4018,8 @@ test "inside test block" {
3992}4018}
3993 {#code_end#}4019 {#code_end#}
3994 <p>4020 <p>
3995 Because of this, when you read Zig code you can always rely on an identifier to consistently mean 4021 Because of this, when you read Zig code you can always rely on an identifier to consistently mean
3996 the same thing within the scope it is defined. Note that you can, however, use the same name if 4022 the same thing within the scope it is defined. Note that you can, however, use the same name if
3997 the scopes are separate:4023 the scopes are separate:
3998 </p>4024 </p>
3999 {#code_begin|test|test_scopes#}4025 {#code_begin|test|test_scopes#}
...@@ -4031,7 +4057,7 @@ test "switch simple" {...@@ -4031,7 +4057,7 @@ test "switch simple" {
4031 1, 2, 3 => 0,4057 1, 2, 3 => 0,
40324058
4033 // Ranges can be specified using the ... syntax. These are inclusive4059 // Ranges can be specified using the ... syntax. These are inclusive
4034 // both ends.4060 // of both ends.
4035 5...100 => 1,4061 5...100 => 1,
40364062
4037 // Branches can be arbitrarily complex.4063 // Branches can be arbitrarily complex.
...@@ -4803,7 +4829,7 @@ test "errdefer unwinding" {...@@ -4803,7 +4829,7 @@ test "errdefer unwinding" {
4803 </p>4829 </p>
4804 {#header_open|Basics#}4830 {#header_open|Basics#}
4805 {#code_begin|test|test_unreachable#}4831 {#code_begin|test|test_unreachable#}
4806// unreachable is used to assert that control flow will never happen upon a4832// unreachable is used to assert that control flow will never reach a
4807// particular location:4833// particular location:
4808test "basic math" {4834test "basic math" {
4809 const x = 1;4835 const x = 1;
...@@ -6771,8 +6797,7 @@ test "variable values" {...@@ -6771,8 +6797,7 @@ test "variable values" {
6771 generic data structure.6797 generic data structure.
6772 </p>6798 </p>
6773 <p>6799 <p>
6774 Here is an example of a generic {#syntax#}List{#endsyntax#} data structure, that we will instantiate with6800 Here is an example of a generic {#syntax#}List{#endsyntax#} data structure.
6775 the type {#syntax#}i32{#endsyntax#}. In Zig we refer to the type as {#syntax#}List(i32){#endsyntax#}.
6776 </p>6801 </p>
6777 {#code_begin|syntax#}6802 {#code_begin|syntax#}
6778fn List(comptime T: type) type {6803fn List(comptime T: type) type {
...@@ -6781,27 +6806,46 @@ fn List(comptime T: type) type {...@@ -6781,27 +6806,46 @@ fn List(comptime T: type) type {
6781 len: usize,6806 len: usize,
6782 };6807 };
6783}6808}
6809
6810// The generic List data structure can be instantiated by passing in a type:
6811var buffer: [10]i32 = undefined;
6812var list = List(i32){
6813 .items = &buffer,
6814 .len = 0,
6815};
6784 {#code_end#}6816 {#code_end#}
6785 <p>6817 <p>
6786 That's it. It's a function that returns an anonymous {#syntax#}struct{#endsyntax#}. For the purposes of error messages6818 That's it. It's a function that returns an anonymous {#syntax#}struct{#endsyntax#}.
6787 and debugging, Zig infers the name {#syntax#}"List(i32)"{#endsyntax#} from the function name and parameters invoked when creating6819 To keep the language small and uniform, all aggregate types in Zig are anonymous.
6820 For the purposes of error messages and debugging, Zig infers the name
6821 {#syntax#}"List(i32)"{#endsyntax#} from the function name and parameters invoked when creating
6788 the anonymous struct.6822 the anonymous struct.
6789 </p>6823 </p>
6790 <p>6824 <p>
6791 To keep the language small and uniform, all aggregate types in Zig are anonymous. To give a type6825 To explicitly give a type a name, we assign it to a constant.
6792 a name, we assign it to a constant:
6793 </p>6826 </p>
6794 {#code_begin|syntax#}6827 {#code_begin|syntax#}
6795const Node = struct {6828const Node = struct {
6796 next: *Node,6829 next: ?*Node,
6797 name: []u8,6830 name: []const u8,
6831};
6832
6833var node_a = Node{
6834 .next = null,
6835 .name = &"Node A",
6836};
6837
6838var node_b = Node{
6839 .next = &node_a,
6840 .name = &"Node B",
6798};6841};
6799 {#code_end#}6842 {#code_end#}
6800 <p>6843 <p>
6801 This works because all top level declarations are order-independent, and as long as there isn't6844 In this example, the {#syntax#}Node{#endsyntax#} struct refers to itself.
6802 an actual infinite regression, values can refer to themselves, directly or indirectly. In this case,6845 This works because all top level declarations are order-independent.
6803 {#syntax#}Node{#endsyntax#} refers to itself as a pointer, which is not actually an infinite regression, so6846 As long as the compiler can determine the size of the struct, it is free to refer to itself.
6804 it works fine.6847 In this case, {#syntax#}Node{#endsyntax#} refers to itself as a pointer, which has a
6848 well-defined size at compile time, so it works fine.
6805 </p>6849 </p>
6806 {#header_close#}6850 {#header_close#}
6807 {#header_open|Case Study: print in Zig#}6851 {#header_open|Case Study: print in Zig#}
...@@ -7214,10 +7258,10 @@ test "global assembly" {...@@ -7214,10 +7258,10 @@ test "global assembly" {
7214 provided explicitly by the caller, and it can be suspended and resumed any number of times.7258 provided explicitly by the caller, and it can be suspended and resumed any number of times.
7215 </p>7259 </p>
7216 <p>7260 <p>
7217 The code following the {#syntax#}async{#endsyntax#} callsite runs immediately after the async 7261 The code following the {#syntax#}async{#endsyntax#} callsite runs immediately after the async
7218 function first suspends. When the return value of the async function is needed, 7262 function first suspends. When the return value of the async function is needed,
7219 the calling code can {#syntax#}await{#endsyntax#} on the async function frame. 7263 the calling code can {#syntax#}await{#endsyntax#} on the async function frame.
7220 This will suspend the calling code until the async function completes, at which point 7264 This will suspend the calling code until the async function completes, at which point
7221 execution resumes just after the {#syntax#}await{#endsyntax#} callsite.7265 execution resumes just after the {#syntax#}await{#endsyntax#} callsite.
7222 </p>7266 </p>
7223 <p>7267 <p>
...@@ -7327,8 +7371,8 @@ fn testResumeFromSuspend(my_result: *i32) void {...@@ -7327,8 +7371,8 @@ fn testResumeFromSuspend(my_result: *i32) void {
7327 in standard code.7371 in standard code.
7328 </p>7372 </p>
7329 <p>7373 <p>
7330 However, it is possible to have an {#syntax#}async{#endsyntax#} call 7374 However, it is possible to have an {#syntax#}async{#endsyntax#} call
7331 without a matching {#syntax#}await{#endsyntax#}. Upon completion of the async function, 7375 without a matching {#syntax#}await{#endsyntax#}. Upon completion of the async function,
7332 execution would continue at the most recent {#syntax#}async{#endsyntax#} callsite or {#syntax#}resume{#endsyntax#} callsite,7376 execution would continue at the most recent {#syntax#}async{#endsyntax#} callsite or {#syntax#}resume{#endsyntax#} callsite,
7333 and the return value of the async function would be lost.7377 and the return value of the async function would be lost.
7334 </p>7378 </p>
...@@ -7365,8 +7409,8 @@ fn func() void {...@@ -7365,8 +7409,8 @@ fn func() void {
7365 </p>7409 </p>
7366 <p>7410 <p>
7367 {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that7411 {#syntax#}await{#endsyntax#} is a suspend point, and takes as an operand anything that
7368 coerces to {#syntax#}anyframe->T{#endsyntax#}. Calling {#syntax#}await{#endsyntax#} on 7412 coerces to {#syntax#}anyframe->T{#endsyntax#}. Calling {#syntax#}await{#endsyntax#} on
7369 the frame of an async function will cause execution to continue at the 7413 the frame of an async function will cause execution to continue at the
7370 {#syntax#}await{#endsyntax#} callsite once the target function completes.7414 {#syntax#}await{#endsyntax#} callsite once the target function completes.
7371 </p>7415 </p>
7372 <p>7416 <p>
...@@ -8291,8 +8335,8 @@ fn internalName() callconv(.C) void {}...@@ -8291,8 +8335,8 @@ fn internalName() callconv(.C) void {}
8291 {#code_begin|obj#}8335 {#code_begin|obj#}
8292export fn foo() void {}8336export fn foo() void {}
8293 {#code_end#}8337 {#code_end#}
8294 <p>Note that even when using {#syntax#}export{#endsyntax#}, {#syntax#}@"foo"{#endsyntax#} syntax can8338 <p>Note that even when using {#syntax#}export{#endsyntax#}, the {#syntax#}@"foo"{#endsyntax#} syntax for
8295 be used to choose any string for the symbol name:</p>8339 {#link|identifiers|Identifiers#} can be used to choose any string for the symbol name:</p>
8296 {#code_begin|obj#}8340 {#code_begin|obj#}
8297export fn @"A function name that is a complete sentence."() void {}8341export fn @"A function name that is a complete sentence."() void {}
8298 {#code_end#}8342 {#code_end#}
...@@ -8591,7 +8635,9 @@ test "integer cast panic" {...@@ -8591,7 +8635,9 @@ test "integer cast panic" {
8591 {#header_open|@intToPtr#}8635 {#header_open|@intToPtr#}
8592 <pre>{#syntax#}@intToPtr(comptime DestType: type, address: usize) DestType{#endsyntax#}</pre>8636 <pre>{#syntax#}@intToPtr(comptime DestType: type, address: usize) DestType{#endsyntax#}</pre>
8593 <p>8637 <p>
8594 Converts an integer to a {#link|pointer|Pointers#}. To convert the other way, use {#link|@ptrToInt#}.8638 Converts an integer to a {#link|pointer|Pointers#}. To convert the other way, use {#link|@ptrToInt#}. Casting an address of 0 to a destination type
8639 which in not {#link|optional|Optional Pointers#} and does not have the {#syntax#}allowzero{#endsyntax#} attribute will result in a
8640 {#link|Pointer Cast Invalid Null#} panic when runtime safety checks are enabled.
8595 </p>8641 </p>
8596 <p>8642 <p>
8597 If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#}8643 If the destination pointer type does not allow address zero and {#syntax#}address{#endsyntax#}
...@@ -8705,7 +8751,8 @@ test "@wasmMemoryGrow" {...@@ -8705,7 +8751,8 @@ test "@wasmMemoryGrow" {
8705 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>8751 <pre>{#syntax#}@mod(numerator: T, denominator: T) T{#endsyntax#}</pre>
8706 <p>8752 <p>
8707 Modulus division. For unsigned integers this is the same as8753 Modulus division. For unsigned integers this is the same as
8708 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}.8754 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
8755 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
8709 </p>8756 </p>
8710 <ul>8757 <ul>
8711 <li>{#syntax#}@mod(-5, 3) == 1{#endsyntax#}</li>8758 <li>{#syntax#}@mod(-5, 3) == 1{#endsyntax#}</li>
...@@ -8723,7 +8770,7 @@ test "@wasmMemoryGrow" {...@@ -8723,7 +8770,7 @@ test "@wasmMemoryGrow" {
8723 If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.8770 If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.
8724 </p>8771 </p>
8725 {#header_close#}8772 {#header_close#}
8726 8773
8727 {#header_open|@panic#}8774 {#header_open|@panic#}
8728 <pre>{#syntax#}@panic(message: []const u8) noreturn{#endsyntax#}</pre>8775 <pre>{#syntax#}@panic(message: []const u8) noreturn{#endsyntax#}</pre>
8729 <p>8776 <p>
...@@ -8830,7 +8877,8 @@ pub const PrefetchOptions = struct {...@@ -8830,7 +8877,8 @@ pub const PrefetchOptions = struct {
8830 <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>8877 <pre>{#syntax#}@rem(numerator: T, denominator: T) T{#endsyntax#}</pre>
8831 <p>8878 <p>
8832 Remainder division. For unsigned integers this is the same as8879 Remainder division. For unsigned integers this is the same as
8833 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}.8880 {#syntax#}numerator % denominator{#endsyntax#}. Caller guarantees {#syntax#}denominator > 0{#endsyntax#}, otherwise the
8881 operation will result in a {#link|Remainder Division by Zero#} when runtime safety checks are enabled.
8834 </p>8882 </p>
8835 <ul>8883 <ul>
8836 <li>{#syntax#}@rem(-5, 3) == -2{#endsyntax#}</li>8884 <li>{#syntax#}@rem(-5, 3) == -2{#endsyntax#}</li>
...@@ -8872,14 +8920,14 @@ pub const PrefetchOptions = struct {...@@ -8872,14 +8920,14 @@ pub const PrefetchOptions = struct {
8872 {#header_close#}8920 {#header_close#}
88738921
8874 {#header_open|@setCold#}8922 {#header_open|@setCold#}
8875 <pre>{#syntax#}@setCold(is_cold: bool){#endsyntax#}</pre>8923 <pre>{#syntax#}@setCold(comptime is_cold: bool){#endsyntax#}</pre>
8876 <p>8924 <p>
8877 Tells the optimizer that a function is rarely called.8925 Tells the optimizer that a function is rarely called.
8878 </p>8926 </p>
8879 {#header_close#}8927 {#header_close#}
88808928
8881 {#header_open|@setEvalBranchQuota#}8929 {#header_open|@setEvalBranchQuota#}
8882 <pre>{#syntax#}@setEvalBranchQuota(new_quota: u32){#endsyntax#}</pre>8930 <pre>{#syntax#}@setEvalBranchQuota(comptime new_quota: u32){#endsyntax#}</pre>
8883 <p>8931 <p>
8884 Changes the maximum number of backwards branches that compile-time code8932 Changes the maximum number of backwards branches that compile-time code
8885 execution can use before giving up and making a compile error.8933 execution can use before giving up and making a compile error.
...@@ -8914,7 +8962,7 @@ test "foo" {...@@ -8914,7 +8962,7 @@ test "foo" {
8914 {#header_close#}8962 {#header_close#}
89158963
8916 {#header_open|@setFloatMode#}8964 {#header_open|@setFloatMode#}
8917 <pre>{#syntax#}@setFloatMode(mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>8965 <pre>{#syntax#}@setFloatMode(comptime mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>
8918 <p>8966 <p>
8919 Sets the floating point mode of the current scope. Possible values are:8967 Sets the floating point mode of the current scope. Possible values are:
8920 </p>8968 </p>
...@@ -8949,7 +8997,7 @@ pub const FloatMode = enum {...@@ -8949,7 +8997,7 @@ pub const FloatMode = enum {
8949 {#header_close#}8997 {#header_close#}
89508998
8951 {#header_open|@setRuntimeSafety#}8999 {#header_open|@setRuntimeSafety#}
8952 <pre>{#syntax#}@setRuntimeSafety(safety_on: bool) void{#endsyntax#}</pre>9000 <pre>{#syntax#}@setRuntimeSafety(comptime safety_on: bool) void{#endsyntax#}</pre>
8953 <p>9001 <p>
8954 Sets whether runtime safety checks are enabled for the scope that contains the function call.9002 Sets whether runtime safety checks are enabled for the scope that contains the function call.
8955 </p>9003 </p>
...@@ -9010,7 +9058,7 @@ test "@setRuntimeSafety" {...@@ -9010,7 +9058,7 @@ test "@setRuntimeSafety" {
9010 </p>9058 </p>
9011 {#see_also|@shlExact|@shrExact#}9059 {#see_also|@shlExact|@shrExact#}
9012 {#header_close#}9060 {#header_close#}
9013 9061
9014 {#header_open|@shrExact#}9062 {#header_open|@shrExact#}
9015 <pre>{#syntax#}@shrExact(value: T, shift_amt: Log2T) T{#endsyntax#}</pre>9063 <pre>{#syntax#}@shrExact(value: T, shift_amt: Log2T) T{#endsyntax#}</pre>
9016 <p>9064 <p>
...@@ -9341,7 +9389,7 @@ fn doTheTest() !void {...@@ -9341,7 +9389,7 @@ fn doTheTest() !void {
9341 If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.9389 If no overflow or underflow occurs, returns {#syntax#}false{#endsyntax#}.
9342 </p>9390 </p>
9343 {#header_close#}9391 {#header_close#}
9344 9392
9345 {#header_open|@tagName#}9393 {#header_open|@tagName#}
9346 <pre>{#syntax#}@tagName(value: anytype) [:0]const u8{#endsyntax#}</pre>9394 <pre>{#syntax#}@tagName(value: anytype) [:0]const u8{#endsyntax#}</pre>
9347 <p>9395 <p>