| ... | @@ -2001,6 +2001,15 @@ or | ... | @@ -2001,6 +2001,15 @@ or |
| 2001 | the pointer is never dereferenced:</p> | 2001 | the pointer is never dereferenced:</p> |
| 2002 | {#code|test_comptime_pointer_conversion.zig#} | 2002 | {#code|test_comptime_pointer_conversion.zig#} |
| 2003 | | 2003 | |
| | 2004 | <p> |
| | 2005 | {#link|@ptrCast#} converts a pointer's element type to another. This |
| | 2006 | creates a new pointer that can cause undetectable illegal behavior |
| | 2007 | depending on the loads and stores that pass through it. Generally, other |
| | 2008 | kinds of type conversions are preferable to |
| | 2009 | {#syntax#}@ptrCast{#endsyntax#} if possible. |
| | 2010 | </p> |
| | 2011 | {#code|test_pointer_casting.zig#} |
| | 2012 | |
| 2004 | {#see_also|Optional Pointers|@ptrFromInt|@intFromPtr|C Pointers#} | 2013 | {#see_also|Optional Pointers|@ptrFromInt|@intFromPtr|C Pointers#} |
| 2005 | {#header_open|volatile#} | 2014 | {#header_open|volatile#} |
| 2006 | <p>Loads and stores are assumed to not have side effects. If a given load or store | 2015 | <p>Loads and stores are assumed to not have side effects. If a given load or store |
| ... | @@ -2015,14 +2024,6 @@ or | ... | @@ -2015,14 +2024,6 @@ or |
| 2015 | Input/Output, it is probably a bug. | 2024 | Input/Output, it is probably a bug. |
| 2016 | </p> | 2025 | </p> |
| 2017 | {#header_close#} | 2026 | {#header_close#} |
| 2018 | <p> | | |
| 2019 | {#link|@ptrCast#} converts a pointer's element type to another. This | | |
| 2020 | creates a new pointer that can cause undetectable illegal behavior | | |
| 2021 | depending on the loads and stores that pass through it. Generally, other | | |
| 2022 | kinds of type conversions are preferable to | | |
| 2023 | {#syntax#}@ptrCast{#endsyntax#} if possible. | | |
| 2024 | </p> | | |
| 2025 | {#code|test_pointer_casting.zig#} | | |
| 2026 | | 2027 | |
| 2027 | {#header_open|Alignment#} | 2028 | {#header_open|Alignment#} |
| 2028 | <p> | 2029 | <p> |