mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
langref: emphasize the use of dereferencing string literals
This commit is contained in:
parent
15a6b27957
commit
27353bb936
1 changed files with 10 additions and 1 deletions
|
|
@ -899,9 +899,18 @@ pub fn main() void {
|
||||||
The type of string literals encodes both the length, and the fact that they are null-terminated,
|
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
|
and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and
|
||||||
{#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}.
|
{#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}.
|
||||||
Dereferencing string literals converts them to {#link|Arrays#}.
|
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal.
|
||||||
|
</p>
|
||||||
|
{#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#}
|
||||||
|
<p>
|
||||||
The encoding of a string in Zig is de-facto assumed to be UTF-8.
|
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
|
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;
|
in source code carry their UTF-8 meaning into the content of the string in the Zig program;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue