diff --git a/doc/langref.html.in b/doc/langref.html.in index d5bbb20f7a..9cd1844e51 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -8,7 +8,7 @@
@@ -410,109 +370,20 @@ pub fn main() !void { } {#code_end#}- The Zig code sample above demonstrates one way to create a program that will output: Hello, world!. -
-
- The code sample shows the contents of a file named hello.zig. Files storing Zig
- source code are {#link|UTF-8 encoded|Source Encoding#} text files. The files storing
- Zig source code must be named with the .zig extension.
-
- Following the hello.zig Zig code sample, the {#link|Zig Build System#} is used
- to build an executable program from the hello.zig source code. Then, the
- hello program is executed showing its output Hello, world!. The
- lines beginning with $ represent command line prompts and a command.
- Everything else is program output.
-
- The code sample begins by adding the {#link|Zig Standard Library#} to the build using the {#link|@import#} builtin function. - The {#syntax#}@import("std"){#endsyntax#} function call creates a structure that represents the Zig Standard Library. - The code then {#link|declares|Container Level Variables#} a - {#link|constant identifier|Assignment#}, named {#syntax#}std{#endsyntax#}, that gives access to the features of the Zig Standard Library. -
-- Next, a {#link|public function|Functions#}, {#syntax#}pub fn{#endsyntax#}, named {#syntax#}main{#endsyntax#} - is declared. The {#syntax#}main{#endsyntax#} function is necessary because it tells the Zig compiler where the program starts. Programs - designed to be executed will need a {#syntax#}pub fn main{#endsyntax#} function. -
- -- A function is a block of any number of statements and expressions, that as a whole, perform a task. - Functions may or may not return data after they are done performing their task. If a function - cannot perform its task, it might return an error. Zig makes all of this explicit. -
-
- In the hello.zig code sample, the main function is declared
- with the {#syntax#}!void{#endsyntax#} return type. This return type is known as an {#link|Error Union Type#}.
- This syntax tells the Zig compiler that the function will either return an
- error or a value. An error union type combines an {#link|Error Set Type#} and any other data type
- (e.g. a {#link|Primitive Type|Primitive Types#} or a user-defined type such as a {#link|struct#}, {#link|enum#}, or {#link|union#}).
- The full form of an error union type is
- <error set type>{#syntax#}!{#endsyntax#}<any data type>. In the code
- sample, the error set type is not explicitly written on the left side of the {#syntax#}!{#endsyntax#} operator.
- When written this way, the error set type is an {#link|inferred error set type|Inferred Error Sets#}. The
- {#syntax#}void{#endsyntax#} after the {#syntax#}!{#endsyntax#} operator
- tells the compiler that the function will not return a value under normal circumstances (i.e. when no errors occur).
-
- In Zig, a function's block of statements and expressions are surrounded by an open curly-brace { and
- close curly-brace }. In hello.zig, the {#syntax#}main{#endsyntax#} function
- contains two statements.
-
- In the first statement, a constant identifier, {#syntax#}stdout{#endsyntax#}, is initialized to represent standard output's - writer. In the second statement, the program tries to print the Hello, world! message to standard output. -
-- Functions sometimes need inputs to perform their task. Inputs are passed, in between parentheses, to functions. These - inputs are also known as arguments. When multiple arguments are passed to a function, they are separated by commas. -
-
- Two arguments are passed to the {#syntax#}stdout.print(){#endsyntax#} function: {#syntax#}"Hello, {s}!\n"{#endsyntax#}
- and {#syntax#}.{"world"}{#endsyntax#}. The first argument is called a format string, which is a string containing one or
- more placeholders. {#syntax#}"Hello, {s}!\n"{#endsyntax#} contains the placeholder {#syntax#}{s}{#endsyntax#}, which is
- replaced with {#syntax#}"world"{#endsyntax#} from the second argument. The file string_literals.zig in
- {#link|String Literals and Unicode Code Point Literals|String Literals and Unicode Code Point Literals#} contains examples of format
- strings that can be used with the {#syntax#}stdout.print(){#endsyntax#} function. The \n inside of
- {#syntax#}"Hello, {s}!\n"{#endsyntax#} is the {#link|escape sequence|Escape Sequences#} for the newline character.
-
- The {#link|try#} expression evaluates the result of {#syntax#}stdout.print{#endsyntax#}. If the result is an error, then the - {#syntax#}try{#endsyntax#} expression will return from {#syntax#}main{#endsyntax#} with the error. Otherwise, the program will continue. - In this case, there are no more statements or expressions left to execute in the {#syntax#}main{#endsyntax#} function, so the program exits. -
-
- In Zig, the standard output writer's {#syntax#}print{#endsyntax#} function is allowed to fail because
- it is actually a function defined as part of a generic Writer. Consider a generic Writer that
- represents writing data to a file. When the disk is full, a write to the file will fail.
- However, we typically do not expect writing text to the standard output to fail. To avoid having
- to handle the failure case of printing to standard output, you can use alternate functions: the
- functions in {#syntax#}std.log{#endsyntax#} for proper logging or the {#syntax#}std.debug.print{#endsyntax#} function.
- This documentation will use the latter option to print to standard error (stderr) and silently return
- on failure. The next code sample, hello_again.zig demonstrates the use of
- {#syntax#}std.debug.print{#endsyntax#}.
+ Most of the time, it more appropriate to write to stderr rather than stdout, and
+ whether or not the message is successfully written to the stream is irrelevant.
+ For this common case, there is a simpler API:
- Note that you can leave off the {#syntax#}!{#endsyntax#} from the return type because {#syntax#}std.debug.print{#endsyntax#} cannot fail. + In this case, the {#syntax#}!{#endsyntax#} may be omitted from the return + type because no errors are returned from the function.
{#see_also|Values|@import|Errors|Root Source File|Source Encoding#} {#header_close#} @@ -896,42 +767,22 @@ pub fn main() void { The type of string literals encodes both the length, and the fact that they are null-terminated, and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}. + Dereferencing string literals converts them to {#link|Arrays#}.- Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal. -
- {#code_begin|syntax|mutable_string_buffer#} -test { - var buffer = [_]u8{0}**256; - const home_dir = "C:/Users/root"; - buffer[0..home_dir.len].* = home_dir.*; -} - {#code_end#} -
- The encoding of a string in Zig is de-facto assumed to be UTF-8.
- Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal
- in source code carry their UTF-8 meaning into the content of the string in the Zig program;
- the bytes are not modified by the compiler.
- However, it is possible to embed non-UTF-8 bytes into a string literal using \xNN notation.
-
- Indexing into a string containing non-ASCII bytes will return individual bytes, whether valid
- UTF-8 or not.
- The {#link|Zig Standard Library#} provides routines for checking the validity of UTF-8 encoded
- strings, accessing their code points and other encoding/decoding related tasks in
- {#syntax#}std.unicode{#endsyntax#}.
+ Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any
+ non-ASCII bytes appearing within a string literal in source code carry
+ their UTF-8 meaning into the content of the string in the Zig program;
+ the bytes are not modified by the compiler. It is possible to embed
+ non-UTF-8 bytes into a string literal using \xNN notation.
Indexing into a string containing non-ASCII bytes returns individual + bytes, whether valid UTF-8 or not.
Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals and Unicode code point literals.
-- In many other programming languages, a Unicode code point literal is called a "character literal". - However, there is no precise technical definition of a "character" - in recent versions of the Unicode specification (as of Unicode 13.0). - In Zig, a Unicode code point literal corresponds to the Unicode definition of a code point. -
{#code_begin|exe|string_literals#} const print = @import("std").debug.print; const mem = @import("std").mem; // will be used to compare bytes @@ -1632,26 +1483,27 @@ pub fn main() void { {#header_open|Table of Operators#}| Name | Syntax | -Relevant Types | -Description | +Types | +Remarks | Example |
|---|---|---|---|---|---|---|
{#syntax#}a + b
-a += b{#endsyntax#} |
+ Addition | +{#syntax#}a + b
+a += b{#endsyntax#} |
|
- Addition. + |
|
|
{#syntax#}a +% b
-a +%= b{#endsyntax#} |
+ Wrapping Addition | +{#syntax#}a +% b
+a +%= b{#endsyntax#} |
|
- Wrapping Addition. + |
|
- {#syntax#}@as(u32, std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}
+ {#syntax#}@as(u32, 0xffffffff) +% 1 == 0{#endsyntax#}
|
{#syntax#}a +| b
-a +|= b{#endsyntax#} |
+ Saturating Addition | +{#syntax#}a +| b
+a +|= b{#endsyntax#} |
|
- Saturating Addition. + |
|
- {#syntax#}@as(u32, std.math.maxInt(u32)) +| 1 == @as(u32, std.math.maxInt(u32)){#endsyntax#}
+ {#syntax#}@as(u8, 255) +| 1 == @as(u8, 255){#endsyntax#}
|
{#syntax#}a - b
-a -= b{#endsyntax#} |
+ Subtraction | +{#syntax#}a - b
+a -= b{#endsyntax#} |
|
- Subtraction. + |
|
|
{#syntax#}a -% b
-a -%= b{#endsyntax#} |
+ Wrapping Subtraction | +{#syntax#}a -% b
+a -%= b{#endsyntax#} |
|
- Wrapping Subtraction. + |
|
- {#syntax#}@as(u32, 0) -% 1 == std.math.maxInt(u32){#endsyntax#}
+ {#syntax#}@as(u8, 0) -% 1 == 255{#endsyntax#}
|
{#syntax#}a -| b
-a -|= b{#endsyntax#} |
+ Saturating Subtraction | +{#syntax#}a -| b
+a -|= b{#endsyntax#} |
|
- Saturating Subtraction. + |
|
|
{#syntax#}-a{#endsyntax#} |
+ Negation | +{#syntax#}-a{#endsyntax#} |
|
- Negation.
|
||
{#syntax#}-%a{#endsyntax#} |
+ Wrapping Negation | +{#syntax#}-%a{#endsyntax#} |
|
- Wrapping Negation.
|
- {#syntax#}-%@as(i32, std.math.minInt(i32)) == std.math.minInt(i32){#endsyntax#}
+ {#syntax#}-%@as(i8, -127) == -127{#endsyntax#}
|
|
{#syntax#}a * b
-a *= b{#endsyntax#} |
+ Multiplication | +{#syntax#}a * b
+a *= b{#endsyntax#} |
|
- Multiplication. + |
|
|
{#syntax#}a *% b
-a *%= b{#endsyntax#} |
+ Wrapping Multiplication | +{#syntax#}a *% b
+a *%= b{#endsyntax#} |
|
- Wrapping Multiplication. + |
|
|
{#syntax#}a *| b
-a *|= b{#endsyntax#} |
+ Saturating Multiplication | +{#syntax#}a *| b
+a *|= b{#endsyntax#} |
|
- Saturating Multiplication. + |
|
|
{#syntax#}a / b
-a /= b{#endsyntax#} |
+ Division | +{#syntax#}a / b
+a /= b{#endsyntax#} |
|
- Division. + |
|
|
{#syntax#}a % b
-a %= b{#endsyntax#} |
+ Remainder Division | +{#syntax#}a % b
+a %= b{#endsyntax#} |
|
- Remainder Division. + |
|
|
{#syntax#}a << b
-a <<= b{#endsyntax#} |
+ Bit Shift Left | +{#syntax#}a << b
+a <<= b{#endsyntax#} |
|
- Bit Shift Left. + |
|
- {#syntax#}1 << 8 == 256{#endsyntax#}
+ {#syntax#}0b1 << 8 == 0b100000000{#endsyntax#}
|
{#syntax#}a <<| b
-a <<|= b{#endsyntax#} |
+ Saturating Bit Shift Left | +{#syntax#}a <<| b
+a <<|= b{#endsyntax#} |
|
- Saturating Bit Shift Left. + |
|
|
{#syntax#}a >> b
-a >>= b{#endsyntax#} |
+ Bit Shift Right | +{#syntax#}a >> b
+a >>= b{#endsyntax#} |
|
- Bit Shift Right. + |
|
- {#syntax#}10 >> 1 == 5{#endsyntax#}
+ {#syntax#}0b1010 >> 1 == 0b101{#endsyntax#}
|
{#syntax#}a & b
-a &= b{#endsyntax#} |
+ Bitwise And | +{#syntax#}a & b
+a &= b{#endsyntax#} |
|
- Bitwise AND. + |
|
|
{#syntax#}a | b
-a |= b{#endsyntax#} |
+ Bitwise Or | +{#syntax#}a | b
+a |= b{#endsyntax#} |
|
- Bitwise OR. + |
|
|
{#syntax#}a ^ b
-a ^= b{#endsyntax#} |
+ Bitwise Xor | +{#syntax#}a ^ b
+a ^= b{#endsyntax#} |
|
- Bitwise XOR. + |
|
|
{#syntax#}~a{#endsyntax#} |
+ Bitwise Not | +{#syntax#}~a{#endsyntax#} |
|
- - Bitwise NOT. - | +
{#syntax#}~@as(u8, 0b10101111) == 0b01010000{#endsyntax#}
|
|
{#syntax#}a orelse b{#endsyntax#} |
+ Defaulting Optional Unwrap | +{#syntax#}a orelse b{#endsyntax#} |
|
If {#syntax#}a{#endsyntax#} is {#syntax#}null{#endsyntax#}, - returns {#syntax#}b{#endsyntax#} ("default value"), - otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. - Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. + returns {#syntax#}b{#endsyntax#} ("default value"), + otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. + Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. |
{#syntax#}const value: ?u32 = null;
@@ -2034,7 +1909,8 @@ unwrapped == 1234{#endsyntax#}
|
|
{#syntax#}a.?{#endsyntax#} |
+ Optional Unwrap | +{#syntax#}a.?{#endsyntax#} |
|
|||
{#syntax#}a catch b
-a catch |err| b{#endsyntax#} |
+ Defaulting Error Unwrap | +{#syntax#}a catch b
+a catch |err| b{#endsyntax#} |
|
If {#syntax#}a{#endsyntax#} is an {#syntax#}error{#endsyntax#}, - returns {#syntax#}b{#endsyntax#} ("default value"), - otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. - Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. - {#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}. + returns {#syntax#}b{#endsyntax#} ("default value"), + otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. + Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. +{#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}. |
{#syntax#}const value: anyerror!u32 = error.Broken;
@@ -2070,51 +1947,55 @@ unwrapped == 1234{#endsyntax#}
|
|
{#syntax#}a and b{#endsyntax#} |
+ Logical And | +{#syntax#}a and b{#endsyntax#} |
|
- If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#} - without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. + If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#} + without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. |
{#syntax#}(false and true) == false{#endsyntax#}
|
|
{#syntax#}a or b{#endsyntax#} |
+ Logical Or | +{#syntax#}a or b{#endsyntax#} |
|
- If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#}, returns {#syntax#}true{#endsyntax#} - without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. + If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#}, + returns {#syntax#}true{#endsyntax#} without evaluating + {#syntax#}b{#endsyntax#}. Otherwise, returns + {#syntax#}b{#endsyntax#}. |
{#syntax#}(false or true) == true{#endsyntax#}
|
|
{#syntax#}!a{#endsyntax#} |
+ Boolean Not | +{#syntax#}!a{#endsyntax#} |
|
- - Boolean NOT. - | +
{#syntax#}!false == true{#endsyntax#}
|
|
{#syntax#}a == b{#endsyntax#} |
+ Equality | +{#syntax#}a == b{#endsyntax#} |
|
|||
{#syntax#}a == null{#endsyntax#} |
+ Null Check | +{#syntax#}a == null{#endsyntax#} |
|
|||
{#syntax#}a != b{#endsyntax#} |
+ Inequality | +{#syntax#}a != b{#endsyntax#} |
|
|||
{#syntax#}a != null{#endsyntax#} |
+ Non-Null Check | +{#syntax#}a != null{#endsyntax#} |
|
|||
{#syntax#}a > b{#endsyntax#} |
+ Greater Than | +{#syntax#}a > b{#endsyntax#} |
|
|||
{#syntax#}a >= b{#endsyntax#} |
+ Greater or Equal | +{#syntax#}a >= b{#endsyntax#} |
|
|||
{#syntax#}a < b{#endsyntax#} |
+ Less Than | +{#syntax#}a < b{#endsyntax#} |
|
|||
{#syntax#}a <= b{#endsyntax#} |
+ Lesser or Equal | +{#syntax#}a <= b{#endsyntax#} |
|
|||
{#syntax#}a ++ b{#endsyntax#} |
+ Array Concatenation | +{#syntax#}a ++ b{#endsyntax#} |
|
- Array concatenation.
|
||
{#syntax#}a ** b{#endsyntax#} |
+ Array Multiplication | +{#syntax#}a ** b{#endsyntax#} |
|
- Array multiplication.
|
||
{#syntax#}a.*{#endsyntax#} |
+ Pointer Dereference | +{#syntax#}a.*{#endsyntax#} |
|
|||
{#syntax#}&a{#endsyntax#} |
+ Address Of | +{#syntax#}&a{#endsyntax#} |
All types | - Address of. |
{#syntax#}const x: u32 = 1234;
@@ -2314,7 +2203,8 @@ ptr.* == 1234{#endsyntax#}
|
|
{#syntax#}a || b{#endsyntax#} |
+ Error Set Merge | +{#syntax#}a || b{#endsyntax#} |
Switch prongs can be marked as {#syntax#}inline{#endsyntax#} to generate - the prong's body for each possible value it could have: + the prong's body for each possible value it could have, making the + captured value {#link|comptime#}. {#code_begin|test|test_inline_switch#} const std = @import("std"); @@ -4324,9 +4215,9 @@ const expectError = std.testing.expectError; fn isFieldOptional(comptime T: type, field_index: usize) !bool { const fields = @typeInfo(T).Struct.fields; return switch (field_index) { - // This prong is analyzed `fields.len - 1` times with `idx` being a - // unique comptime-known value each time. - inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, + // This prong is analyzed twice with `idx` being a + // comptime-known value each time. + inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .Optional, else => return error.IndexOutOfBounds, }; } @@ -4350,6 +4241,16 @@ fn isFieldOptionalUnrolled(field_index: usize) !bool { 1 => true, else => return error.IndexOutOfBounds, }; +} + {#code_end#} +The {#syntax#}inline{#endsyntax#} keyword may also be combined with ranges: + {#code_begin|syntax|inline_prong_range#} +fn isFieldOptional(comptime T: type, field_index: usize) !bool { + const fields = @typeInfo(T).Struct.fields; + return switch (field_index) { + inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, + else => return error.IndexOutOfBounds, + }; } {#code_end#}@@ -7853,7 +7754,7 @@ comptime { {#header_close#} {#header_open|@atomicLoad#} - {#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}
+ {#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: AtomicOrder) T{#endsyntax#}
This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value. @@ -7861,11 +7762,12 @@ comptime { {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, an integer or an enum. +{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#} {#header_close#} {#header_open|@atomicRmw#} -{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}
+ {#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: AtomicRmwOp, operand: T, comptime ordering: AtomicOrder) T{#endsyntax#}
This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically modifies the value and returns the previous value. @@ -7874,27 +7776,13 @@ comptime { {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, an integer or an enum. -- Supported values for the {#syntax#}op{#endsyntax#} parameter: - -
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. +{#syntax#}AtomicRmwOp{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicRmwOp{#endsyntax#}. {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#} {#header_close#} {#header_open|@atomicStore#} -{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void{#endsyntax#}
+ {#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: AtomicOrder) void{#endsyntax#}
This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value. @@ -7902,6 +7790,7 @@ comptime { {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, an integer or an enum. +{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#} {#header_close#} @@ -8178,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v an integer or an enum.{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#} +{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#} {#header_close#} @@ -8209,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val an integer or an enum.{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#} +{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#} {#header_close#} @@ -8499,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {}The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations. -- {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. - +{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#} {#header_close#} @@ -8909,7 +8798,7 @@ test "@wasmMemoryGrow" { {#header_close#} {#header_open|@prefetch#} -{#syntax#}@prefetch(ptr: anytype, comptime options: std.builtin.PrefetchOptions) void{#endsyntax#}
+ {#syntax#}@prefetch(ptr: anytype, comptime options: PrefetchOptions) void{#endsyntax#}
This builtin tells the compiler to emit a prefetch instruction if supported by the target CPU. If the target CPU does not support the requested prefetch instruction, @@ -8921,37 +8810,7 @@ test "@wasmMemoryGrow" { address to prefetch. This function does not dereference the pointer, it is perfectly legal to pass a pointer to invalid memory to this function and no illegal behavior will result. -- The {#syntax#}options{#endsyntax#} argument is the following struct: - - {#code_begin|syntax|builtin#} -/// This data structure is used by the Zig language code generation and -/// therefore must be kept in sync with the compiler implementation. -pub const PrefetchOptions = struct { - /// Whether the prefetch should prepare for a read or a write. - rw: Rw = .read, - /// The data's locality in an inclusive range from 0 to 3. - /// - /// 0 means no temporal locality. That is, the data can be immediately - /// dropped from the cache after it is accessed. - /// - /// 3 means high temporal locality. That is, the data should be kept in - /// the cache as it is likely to be accessed again soon. - locality: u2 = 3, - /// The cache that the prefetch should be preformed on. - cache: Cache = .data, - - pub const Rw = enum(u1) { - read, - write, - }; - - pub const Cache = enum(u1) { - instruction, - data, - }; -}; - {#code_end#} +{#syntax#}PrefetchOptions{#endsyntax#} can be found with {#syntax#}@import("std").builtin.PrefetchOptions{#endsyntax#}. {#header_close#} {#header_open|@ptrCast#} @@ -9080,16 +8939,8 @@ test "foo" { {#header_close#} {#header_open|@setFloatMode#} -{#syntax#}@setFloatMode(comptime mode: @import("std").builtin.FloatMode) void{#endsyntax#}
- - Sets the floating point mode of the current scope. Possible values are: - - {#code_begin|syntax|FloatMode#} -pub const FloatMode = enum { - Strict, - Optimized, -}; - {#code_end#} +{#syntax#}@setFloatMode(comptime mode: FloatMode) void{#endsyntax#}
+ Changes the current scope's rules about how floating point operations are defined.
|