From 8662c0ff43aad7191b063047c71384e868086d6f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 18 Jan 2024 20:58:35 -0700 Subject: [PATCH] langref: avoid the ambiguous word "safe" See #2402 --- doc/langref.html.in | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index f774c0bfdc..f3cb0fbae8 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -2788,9 +2788,11 @@ test "volatile" {

{#header_close#}

- To convert one pointer type to another, use {#link|@ptrCast#}. This is an unsafe - operation that Zig cannot protect you against. Use {#syntax#}@ptrCast{#endsyntax#} only when other - conversions are not possible. + {#link|@ptrCast#} converts a pointer's element type to another. This + creates a new pointer that can cause undetectable illegal behavior + depending on the loads and stores that pass through it. Generally, other + kinds of type conversions are preferable to + {#syntax#}@ptrCast{#endsyntax#} if possible.

{#code_begin|test|test_pointer_casting#} const std = @import("std"); @@ -8592,7 +8594,8 @@ test "decl access by string" {
{#syntax#}@floatFromInt(int: anytype) anytype{#endsyntax#}

Converts an integer to the closest floating point representation. The return type is the inferred result type. - To convert the other way, use {#link|@intFromFloat#}. This cast is always safe. + To convert the other way, use {#link|@intFromFloat#}. This operation is legal + for all values of all integer types.

{#header_close#}