authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-26 15:48:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-26 15:48:42-04:00
log4de60dde6ed734acbc428887866ae3d528abbd37
tree4569988a9bf24a088f81dea8592342ee37e3ab84
parent11ca38a4e9c637bf6ff635f4f62634edaf89f853

langref: explicit cast section


1 files changed, 30 insertions(+), 1 deletions(-)

doc/langref.html.in+30-1
......@@ -3602,6 +3602,10 @@ test "implicit cast - invoke a type as a function" {
36023602 var b = u16(a);
36033603}
36043604 {#code_end#}
3605 <p>
3606 Implicit casts are only allowed when it is completely unambiguous how to get from one type to another,
3607 and the transformation is guaranteed to be safe.
3608 </p>
36053609 {#header_open|Implicit Cast: Stricter Qualification#}
36063610 <p>
36073611 Values which have the same representation at runtime can be cast to increase the strictness
......@@ -3722,7 +3726,32 @@ test "float widening" {
37223726 {#header_close#}
37233727
37243728 {#header_open|Explicit Casts#}
3725 <p>TODO</p>
3729 <p>
3730 Explicit casts are performed via {#link|Builtin Functions#}.
3731 Some explicit casts are safe; some are not.
3732 Some explicit casts perform language-level assertions; some do not.
3733 Some explicit casts are no-ops at runtime; some are not.
3734 </p>
3735 <ul>
3736 <li>{#link|@bitCast#} - change type but maintain bit representation</li>
3737 <li>{#link|@alignCast#} - make a pointer have more alignment</li>
3738 <li>{#link|@boolToInt#} - convert true to 1 and false to 0</li>
3739 <li>{#link|@bytesToSlice#} - convert a slice of bytes to a slice of another type</li>
3740 <li>{#link|@enumToInt#} - obtain the integer tag value of an enum or tagged union</li>
3741 <li>{#link|@errSetCast#} - convert to a smaller error set</li>
3742 <li>{#link|@errorToInt#} - obtain the integer value of an error code</li>
3743 <li>{#link|@floatCast#} - convert a larger float to a smaller float</li>
3744 <li>{#link|@floatToInt#} - obtain the integer part of a float value</li>
3745 <li>{#link|@intCast#} - convert between integer types</li>
3746 <li>{#link|@intToEnum#} - obtain an enum value based on its integer tag value</li>
3747 <li>{#link|@intToError#} - obtain an error code based on its integer value</li>
3748 <li>{#link|@intToFloat#} - convert an integer to a float value</li>
3749 <li>{#link|@intToPtr#} - convert an address to a pointer</li>
3750 <li>{#link|@ptrCast#} - convert between pointer types</li>
3751 <li>{#link|@ptrToInt#} - obtain the address of a pointer</li>
3752 <li>{#link|@sliceToBytes#} - convert a slice of anything to a slice of bytes</li>
3753 <li>{#link|@truncate#} - convert between integer types, chopping off bits</li>
3754 </ul>
37263755 {#header_close#}
37273756
37283757 {#header_open|Peer Type Resolution#}