| ... | ... | @@ -33,7 +33,7 @@ |
| 33 | 33 | .file { |
| 34 | 34 | text-decoration: underline; |
| 35 | 35 | } |
| 36 | | pre { |
| 36 | code { |
| 37 | 37 | font-size: 12pt; |
| 38 | 38 | } |
| 39 | 39 | @media screen and (min-width: 28.75em) { |
| ... | ... | @@ -102,10 +102,14 @@ pub fn main() -> %void { |
| 102 | 102 | {#code_begin|exe|hello#} |
| 103 | 103 | const warn = @import("std").debug.warn; |
| 104 | 104 | |
| 105 | | pub fn main() -> %void { |
| 105 | pub fn main() -> void { |
| 106 | 106 | warn("Hello, world!\n"); |
| 107 | 107 | } |
| 108 | 108 | {#code_end#} |
| 109 | <p> |
| 110 | Note that we also left off the <code class="zig">%</code> from the return type. |
| 111 | In Zig, if your main function cannot fail, you may use the <code class="zig">void</code> return type. |
| 112 | </p> |
| 109 | 113 | {#see_also|Values|@import|Errors|Root Source File#} |
| 110 | 114 | {#header_close#} |
| 111 | 115 | {#header_open|Source Encoding#} |
| ... | ... | @@ -621,7 +625,6 @@ fn divide(a: i32, b: i32) -> i32 { |
| 621 | 625 | {#header_close#} |
| 622 | 626 | {#header_close#} |
| 623 | 627 | {#header_open|Floats#} |
| 624 | | {#header_close#} |
| 625 | 628 | {#header_open|Float Literals#} |
| 626 | 629 | {#code_begin|syntax#} |
| 627 | 630 | const floating_point = 123.0E+77; |
| ... | ... | @@ -668,6 +671,7 @@ pub fn main() -> %void { |
| 668 | 671 | {#code_end#} |
| 669 | 672 | {#see_also|@setFloatMode|Division by Zero#} |
| 670 | 673 | {#header_close#} |
| 674 | {#header_close#} |
| 671 | 675 | {#header_open|Operators#} |
| 672 | 676 | {#header_open|Table of Operators#} |
| 673 | 677 | <table> |
| ... | ... | @@ -690,13 +694,13 @@ pub fn main() -> %void { |
| 690 | 694 | a += b</code></pre></td> |
| 691 | 695 | <td> |
| 692 | 696 | <ul> |
| 693 | | <li><a href="#integers">Integers</a></li> |
| 694 | | <li><a href="#floats">Floats</a></li> |
| 697 | <li>{#link|Integers#}</li> |
| 698 | <li>{#link|Floats#}</li> |
| 695 | 699 | </ul> |
| 696 | 700 | </td> |
| 697 | 701 | <td>Addition. |
| 698 | 702 | <ul> |
| 699 | | <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li> |
| 703 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 700 | 704 | </ul> |
| 701 | 705 | </td> |
| 702 | 706 | <td> |
| ... | ... | @@ -708,7 +712,7 @@ a += b</code></pre></td> |
| 708 | 712 | a +%= b</code></pre></td> |
| 709 | 713 | <td> |
| 710 | 714 | <ul> |
| 711 | | <li><a href="#integers">Integers</a></li> |
| 715 | <li>{#link|Integers#}</li> |
| 712 | 716 | </ul> |
| 713 | 717 | </td> |
| 714 | 718 | <td>Wrapping Addition. |
| ... | ... | @@ -725,13 +729,13 @@ a +%= b</code></pre></td> |
| 725 | 729 | a -= b</code></pre></td> |
| 726 | 730 | <td> |
| 727 | 731 | <ul> |
| 728 | | <li><a href="#integers">Integers</a></li> |
| 729 | | <li><a href="#floats">Floats</a></li> |
| 732 | <li>{#link|Integers#}</li> |
| 733 | <li>{#link|Floats#}</li> |
| 730 | 734 | </ul> |
| 731 | 735 | </td> |
| 732 | 736 | <td>Subtraction. |
| 733 | 737 | <ul> |
| 734 | | <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li> |
| 738 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 735 | 739 | </ul> |
| 736 | 740 | </td> |
| 737 | 741 | <td> |
| ... | ... | @@ -743,7 +747,7 @@ a -= b</code></pre></td> |
| 743 | 747 | a -%= b</code></pre></td> |
| 744 | 748 | <td> |
| 745 | 749 | <ul> |
| 746 | | <li><a href="#integers">Integers</a></li> |
| 750 | <li>{#link|Integers#}</li> |
| 747 | 751 | </ul> |
| 748 | 752 | </td> |
| 749 | 753 | <td>Wrapping Subtraction. |
| ... | ... | @@ -759,14 +763,14 @@ a -%= b</code></pre></td> |
| 759 | 763 | <td><pre><code class="zig">-a<code></pre></td> |
| 760 | 764 | <td> |
| 761 | 765 | <ul> |
| 762 | | <li><a href="#integers">Integers</a></li> |
| 763 | | <li><a href="#floats">Floats</a></li> |
| 766 | <li>{#link|Integers#}</li> |
| 767 | <li>{#link|Floats#}</li> |
| 764 | 768 | </ul> |
| 765 | 769 | </td> |
| 766 | 770 | <td> |
| 767 | 771 | Negation. |
| 768 | 772 | <ul> |
| 769 | | <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li> |
| 773 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 770 | 774 | </ul> |
| 771 | 775 | </td> |
| 772 | 776 | <td> |
| ... | ... | @@ -777,7 +781,7 @@ a -%= b</code></pre></td> |
| 777 | 781 | <td><pre><code class="zig">-%a<code></pre></td> |
| 778 | 782 | <td> |
| 779 | 783 | <ul> |
| 780 | | <li><a href="#integers">Integers</a></li> |
| 784 | <li>{#link|Integers#}</li> |
| 781 | 785 | </ul> |
| 782 | 786 | </td> |
| 783 | 787 | <td> |
| ... | ... | @@ -795,13 +799,13 @@ a -%= b</code></pre></td> |
| 795 | 799 | a *= b</code></pre></td> |
| 796 | 800 | <td> |
| 797 | 801 | <ul> |
| 798 | | <li><a href="#integers">Integers</a></li> |
| 799 | | <li><a href="#floats">Floats</a></li> |
| 802 | <li>{#link|Integers#}</li> |
| 803 | <li>{#link|Floats#}</li> |
| 800 | 804 | </ul> |
| 801 | 805 | </td> |
| 802 | 806 | <td>Multiplication. |
| 803 | 807 | <ul> |
| 804 | | <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li> |
| 808 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 805 | 809 | </ul> |
| 806 | 810 | </td> |
| 807 | 811 | <td> |
| ... | ... | @@ -813,7 +817,7 @@ a *= b</code></pre></td> |
| 813 | 817 | a *%= b</code></pre></td> |
| 814 | 818 | <td> |
| 815 | 819 | <ul> |
| 816 | | <li><a href="#integers">Integers</a></li> |
| 820 | <li>{#link|Integers#}</li> |
| 817 | 821 | </ul> |
| 818 | 822 | </td> |
| 819 | 823 | <td>Wrapping Multiplication. |
| ... | ... | @@ -830,19 +834,19 @@ a *%= b</code></pre></td> |
| 830 | 834 | a /= b</code></pre></td> |
| 831 | 835 | <td> |
| 832 | 836 | <ul> |
| 833 | | <li><a href="#integers">Integers</a></li> |
| 834 | | <li><a href="#floats">Floats</a></li> |
| 837 | <li>{#link|Integers#}</li> |
| 838 | <li>{#link|Floats#}</li> |
| 835 | 839 | </ul> |
| 836 | 840 | </td> |
| 837 | 841 | <td>Divison. |
| 838 | 842 | <ul> |
| 839 | | <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li> |
| 840 | | <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li> |
| 841 | | <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for floats in <a href="#float-operations">FloatMode.Optimized Mode</a>.</li> |
| 843 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 844 | <li>Can cause {#link|Division by Zero#} for integers.</li> |
| 845 | <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li> |
| 842 | 846 | <li>For non-compile-time-known signed integers, must use |
| 843 | | <a href="#builtin-divTrunc">@divTrunc</a>, |
| 844 | | <a href="#builtin-divFloor">@divFloor</a>, or |
| 845 | | <a href="#builtin-divExact">@divExact</a> instead of <code>/</code>. |
| 847 | {#link|@divTrunc#}, |
| 848 | {#link|@divFloor#}, or |
| 849 | {#link|@divExact#} instead of <code>/</code>. |
| 846 | 850 | </li> |
| 847 | 851 | </ul> |
| 848 | 852 | </td> |
| ... | ... | @@ -855,17 +859,17 @@ a /= b</code></pre></td> |
| 855 | 859 | a %= b</code></pre></td> |
| 856 | 860 | <td> |
| 857 | 861 | <ul> |
| 858 | | <li><a href="#integers">Integers</a></li> |
| 859 | | <li><a href="#floats">Floats</a></li> |
| 862 | <li>{#link|Integers#}</li> |
| 863 | <li>{#link|Floats#}</li> |
| 860 | 864 | </ul> |
| 861 | 865 | </td> |
| 862 | 866 | <td>Remainder Division. |
| 863 | 867 | <ul> |
| 864 | | <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li> |
| 865 | | <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for floats in <a href="#float-operations">FloatMode.Optimized Mode</a>.</li> |
| 868 | <li>Can cause {#link|Division by Zero#} for integers.</li> |
| 869 | <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li> |
| 866 | 870 | <li>For non-compile-time-known signed integers, must use |
| 867 | | <a href="#builtin-rem">@rem</a> or |
| 868 | | <a href="#builtin-mod">@mod</a> instead of <code>%</code>. |
| 871 | {#link|@rem#} or |
| 872 | {#link|@mod#} instead of <code>%</code>. |
| 869 | 873 | </li> |
| 870 | 874 | </ul> |
| 871 | 875 | </td> |
| ... | ... | @@ -878,13 +882,13 @@ a %= b</code></pre></td> |
| 878 | 882 | a &lt;&lt;= b</code></pre></td> |
| 879 | 883 | <td> |
| 880 | 884 | <ul> |
| 881 | | <li><a href="#integers">Integers</a></li> |
| 885 | <li>{#link|Integers#}</li> |
| 882 | 886 | </ul> |
| 883 | 887 | </td> |
| 884 | 888 | <td>Bit Shift Left. |
| 885 | 889 | <ul> |
| 886 | | <li>See also <a href="#builtin-shlExact">@shlExact</a>.</li> |
| 887 | | <li>See also <a href="#builtin-shlWithOverflow">@shlWithOverflow</a>.</li> |
| 890 | <li>See also {#link|@shlExact#}.</li> |
| 891 | <li>See also {#link|@shlWithOverflow#}.</li> |
| 888 | 892 | </ul> |
| 889 | 893 | </td> |
| 890 | 894 | <td> |
| ... | ... | @@ -896,12 +900,12 @@ a &lt;&lt;= b</code></pre></td> |
| 896 | 900 | a &gt;&gt;= b</code></pre></td> |
| 897 | 901 | <td> |
| 898 | 902 | <ul> |
| 899 | | <li><a href="#integers">Integers</a></li> |
| 903 | <li>{#link|Integers#}</li> |
| 900 | 904 | </ul> |
| 901 | 905 | </td> |
| 902 | 906 | <td>Bit Shift Right. |
| 903 | 907 | <ul> |
| 904 | | <li>See also <a href="#builtin-shrExact">@shrExact</a>.</li> |
| 908 | <li>See also {#link|@shrExact#}.</li> |
| 905 | 909 | </ul> |
| 906 | 910 | </td> |
| 907 | 911 | <td> |
| ... | ... | @@ -913,7 +917,7 @@ a &gt;&gt;= b</code></pre></td> |
| 913 | 917 | a &amp;= b</code></pre></td> |
| 914 | 918 | <td> |
| 915 | 919 | <ul> |
| 916 | | <li><a href="#integers">Integers</a></li> |
| 920 | <li>{#link|Integers#}</li> |
| 917 | 921 | </ul> |
| 918 | 922 | </td> |
| 919 | 923 | <td>Bitwise AND. |
| ... | ... | @@ -927,7 +931,7 @@ a &amp;= b</code></pre></td> |
| 927 | 931 | a |= b</code></pre></td> |
| 928 | 932 | <td> |
| 929 | 933 | <ul> |
| 930 | | <li><a href="#integers">Integers</a></li> |
| 934 | <li>{#link|Integers#}</li> |
| 931 | 935 | </ul> |
| 932 | 936 | </td> |
| 933 | 937 | <td>Bitwise OR. |
| ... | ... | @@ -941,7 +945,7 @@ a |= b</code></pre></td> |
| 941 | 945 | a ^= b</code></pre></td> |
| 942 | 946 | <td> |
| 943 | 947 | <ul> |
| 944 | | <li><a href="#integers">Integers</a></li> |
| 948 | <li>{#link|Integers#}</li> |
| 945 | 949 | </ul> |
| 946 | 950 | </td> |
| 947 | 951 | <td>Bitwise XOR. |
| ... | ... | @@ -954,7 +958,7 @@ a ^= b</code></pre></td> |
| 954 | 958 | <td><pre><code class="zig">~a<code></pre></td> |
| 955 | 959 | <td> |
| 956 | 960 | <ul> |
| 957 | | <li><a href="#integers">Integers</a></li> |
| 961 | <li>{#link|Integers#}</li> |
| 958 | 962 | </ul> |
| 959 | 963 | </td> |
| 960 | 964 | <td> |
| ... | ... | @@ -968,13 +972,13 @@ a ^= b</code></pre></td> |
| 968 | 972 | <td><pre><code class="zig">a ?? b</code></pre></td> |
| 969 | 973 | <td> |
| 970 | 974 | <ul> |
| 971 | | <li><a href="#nullables">Nullables</a></li> |
| 975 | <li>{#link|Nullables#}</li> |
| 972 | 976 | </ul> |
| 973 | 977 | </td> |
| 974 | 978 | <td>If <code>a</code> is <code>null</code>, |
| 975 | 979 | returns <code>b</code> ("default value"), |
| 976 | 980 | otherwise returns the unwrapped value of <code>a</code>. |
| 977 | | Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>. |
| 981 | Note that <code>b</code> may be a value of type {#link|noreturn#}. |
| 978 | 982 | </td> |
| 979 | 983 | <td> |
| 980 | 984 | <pre><code class="zig">const value: ?u32 = null; |
| ... | ... | @@ -986,7 +990,7 @@ unwrapped == 1234</code></pre> |
| 986 | 990 | <td><pre><code class="zig">??a</code></pre></td> |
| 987 | 991 | <td> |
| 988 | 992 | <ul> |
| 989 | | <li><a href="#nullables">Nullables</a></li> |
| 993 | <li>{#link|Nullables#}</li> |
| 990 | 994 | </ul> |
| 991 | 995 | </td> |
| 992 | 996 | <td> |
| ... | ... | @@ -1003,13 +1007,13 @@ unwrapped == 1234</code></pre> |
| 1003 | 1007 | a catch |err| b</code></pre></td> |
| 1004 | 1008 | <td> |
| 1005 | 1009 | <ul> |
| 1006 | | <li><a href="#errors">Error Unions</a></li> |
| 1010 | <li>{#link|Error Unions|Errors#}</li> |
| 1007 | 1011 | </ul> |
| 1008 | 1012 | </td> |
| 1009 | 1013 | <td>If <code>a</code> is an <code>error</code>, |
| 1010 | 1014 | returns <code>b</code> ("default value"), |
| 1011 | 1015 | otherwise returns the unwrapped value of <code>a</code>. |
| 1012 | | Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>. |
| 1016 | Note that <code>b</code> may be a value of type {#link|noreturn#}. |
| 1013 | 1017 | <code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>. |
| 1014 | 1018 | </td> |
| 1015 | 1019 | <td> |
| ... | ... | @@ -1022,7 +1026,7 @@ unwrapped == 1234</code></pre> |
| 1022 | 1026 | <td><pre><code class="zig">a and b<code></pre></td> |
| 1023 | 1027 | <td> |
| 1024 | 1028 | <ul> |
| 1025 | | <li><a href="#primitive-types">bool</a></li> |
| 1029 | <li>{#link|bool|Primitive Types#}</li> |
| 1026 | 1030 | </ul> |
| 1027 | 1031 | </td> |
| 1028 | 1032 | <td> |
| ... | ... | @@ -1037,7 +1041,7 @@ unwrapped == 1234</code></pre> |
| 1037 | 1041 | <td><pre><code class="zig">a or b<code></pre></td> |
| 1038 | 1042 | <td> |
| 1039 | 1043 | <ul> |
| 1040 | | <li><a href="#primitive-types">bool</a></li> |
| 1044 | <li>{#link|bool|Primitive Types#}</li> |
| 1041 | 1045 | </ul> |
| 1042 | 1046 | </td> |
| 1043 | 1047 | <td> |
| ... | ... | @@ -1052,7 +1056,7 @@ unwrapped == 1234</code></pre> |
| 1052 | 1056 | <td><pre><code class="zig">!a<code></pre></td> |
| 1053 | 1057 | <td> |
| 1054 | 1058 | <ul> |
| 1055 | | <li><a href="#primitive-types">bool</a></li> |
| 1059 | <li>{#link|bool|Primitive Types#}</li> |
| 1056 | 1060 | </ul> |
| 1057 | 1061 | </td> |
| 1058 | 1062 | <td> |
| ... | ... | @@ -1066,10 +1070,10 @@ unwrapped == 1234</code></pre> |
| 1066 | 1070 | <td><pre><code class="zig">a == b<code></pre></td> |
| 1067 | 1071 | <td> |
| 1068 | 1072 | <ul> |
| 1069 | | <li><a href="#integers">Integers</a></li> |
| 1070 | | <li><a href="#floats">Floats</a></li> |
| 1071 | | <li><a href="#primitive-types">bool</a></li> |
| 1072 | | <li><a href="#primitive-types">type</a></li> |
| 1073 | <li>{#link|Integers#}</li> |
| 1074 | <li>{#link|Floats#}</li> |
| 1075 | <li>{#link|bool|Primitive Types#}</li> |
| 1076 | <li>{#link|type|Primitive Types#}</li> |
| 1073 | 1077 | </ul> |
| 1074 | 1078 | </td> |
| 1075 | 1079 | <td> |
| ... | ... | @@ -1083,7 +1087,7 @@ unwrapped == 1234</code></pre> |
| 1083 | 1087 | <td><pre><code class="zig">a == null<code></pre></td> |
| 1084 | 1088 | <td> |
| 1085 | 1089 | <ul> |
| 1086 | | <li><a href="#nullables">Nullables</a></li> |
| 1090 | <li>{#link|Nullables#}</li> |
| 1087 | 1091 | </ul> |
| 1088 | 1092 | </td> |
| 1089 | 1093 | <td> |
| ... | ... | @@ -1098,10 +1102,10 @@ value == null</code></pre> |
| 1098 | 1102 | <td><pre><code class="zig">a != b<code></pre></td> |
| 1099 | 1103 | <td> |
| 1100 | 1104 | <ul> |
| 1101 | | <li><a href="#integers">Integers</a></li> |
| 1102 | | <li><a href="#floats">Floats</a></li> |
| 1103 | | <li><a href="#primitive-types">bool</a></li> |
| 1104 | | <li><a href="#primitive-types">type</a></li> |
| 1105 | <li>{#link|Integers#}</li> |
| 1106 | <li>{#link|Floats#}</li> |
| 1107 | <li>{#link|bool|Primitive Types#}</li> |
| 1108 | <li>{#link|type|Primitive Types#}</li> |
| 1105 | 1109 | </ul> |
| 1106 | 1110 | </td> |
| 1107 | 1111 | <td> |
| ... | ... | @@ -1115,8 +1119,8 @@ value == null</code></pre> |
| 1115 | 1119 | <td><pre><code class="zig">a &gt; b<code></pre></td> |
| 1116 | 1120 | <td> |
| 1117 | 1121 | <ul> |
| 1118 | | <li><a href="#integers">Integers</a></li> |
| 1119 | | <li><a href="#floats">Floats</a></li> |
| 1122 | <li>{#link|Integers#}</li> |
| 1123 | <li>{#link|Floats#}</li> |
| 1120 | 1124 | </ul> |
| 1121 | 1125 | </td> |
| 1122 | 1126 | <td> |
| ... | ... | @@ -1130,8 +1134,8 @@ value == null</code></pre> |
| 1130 | 1134 | <td><pre><code class="zig">a &gt;= b<code></pre></td> |
| 1131 | 1135 | <td> |
| 1132 | 1136 | <ul> |
| 1133 | | <li><a href="#integers">Integers</a></li> |
| 1134 | | <li><a href="#floats">Floats</a></li> |
| 1137 | <li>{#link|Integers#}</li> |
| 1138 | <li>{#link|Floats#}</li> |
| 1135 | 1139 | </ul> |
| 1136 | 1140 | </td> |
| 1137 | 1141 | <td> |
| ... | ... | @@ -1145,8 +1149,8 @@ value == null</code></pre> |
| 1145 | 1149 | <td><pre><code class="zig">a &lt; b<code></pre></td> |
| 1146 | 1150 | <td> |
| 1147 | 1151 | <ul> |
| 1148 | | <li><a href="#integers">Integers</a></li> |
| 1149 | | <li><a href="#floats">Floats</a></li> |
| 1152 | <li>{#link|Integers#}</li> |
| 1153 | <li>{#link|Floats#}</li> |
| 1150 | 1154 | </ul> |
| 1151 | 1155 | </td> |
| 1152 | 1156 | <td> |
| ... | ... | @@ -1160,8 +1164,8 @@ value == null</code></pre> |
| 1160 | 1164 | <td><pre><code class="zig">a &lt;= b<code></pre></td> |
| 1161 | 1165 | <td> |
| 1162 | 1166 | <ul> |
| 1163 | | <li><a href="#integers">Integers</a></li> |
| 1164 | | <li><a href="#floats">Floats</a></li> |
| 1167 | <li>{#link|Integers#}</li> |
| 1168 | <li>{#link|Floats#}</li> |
| 1165 | 1169 | </ul> |
| 1166 | 1170 | </td> |
| 1167 | 1171 | <td> |
| ... | ... | @@ -1175,13 +1179,13 @@ value == null</code></pre> |
| 1175 | 1179 | <td><pre><code class="zig">a ++ b<code></pre></td> |
| 1176 | 1180 | <td> |
| 1177 | 1181 | <ul> |
| 1178 | | <li><a href="#arrays">Arrays</a></li> |
| 1182 | <li>{#link|Arrays#}</li> |
| 1179 | 1183 | </ul> |
| 1180 | 1184 | </td> |
| 1181 | 1185 | <td> |
| 1182 | 1186 | Array concatenation. |
| 1183 | 1187 | <ul> |
| 1184 | | <li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>. |
| 1188 | <li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}. |
| 1185 | 1189 | </ul> |
| 1186 | 1190 | </td> |
| 1187 | 1191 | <td> |
| ... | ... | @@ -1196,13 +1200,13 @@ mem.eql(u32, together, []u32{1,2,3,4})</code></pre> |
| 1196 | 1200 | <td><pre><code class="zig">a ** b<code></pre></td> |
| 1197 | 1201 | <td> |
| 1198 | 1202 | <ul> |
| 1199 | | <li><a href="#arrays">Arrays</a></li> |
| 1203 | <li>{#link|Arrays#}</li> |
| 1200 | 1204 | </ul> |
| 1201 | 1205 | </td> |
| 1202 | 1206 | <td> |
| 1203 | 1207 | Array multiplication. |
| 1204 | 1208 | <ul> |
| 1205 | | <li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>. |
| 1209 | <li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}. |
| 1206 | 1210 | </ul> |
| 1207 | 1211 | </td> |
| 1208 | 1212 | <td> |
| ... | ... | @@ -1215,7 +1219,7 @@ mem.eql(u8, pattern, "ababab")</code></pre> |
| 1215 | 1219 | <td><pre><code class="zig">*a<code></pre></td> |
| 1216 | 1220 | <td> |
| 1217 | 1221 | <ul> |
| 1218 | | <li><a href="#pointers">Pointers</a></li> |
| 1222 | <li>{#link|Pointers#}</li> |
| 1219 | 1223 | </ul> |
| 1220 | 1224 | </td> |
| 1221 | 1225 | <td> |
| ... | ... | @@ -1504,7 +1508,7 @@ test "pointer child type" { |
| 1504 | 1508 | Each type has an <strong>alignment</strong> - a number of bytes such that, |
| 1505 | 1509 | when a value of the type is loaded from or stored to memory, |
| 1506 | 1510 | the memory address must be evenly divisible by this number. You can use |
| 1507 | | <a href="#builtin-alignOf">@alignOf</a> to find out this value for any type. |
| 1511 | {#link|@alignOf#} to find out this value for any type. |
| 1508 | 1512 | </p> |
| 1509 | 1513 | <p> |
| 1510 | 1514 | Alignment depends on the CPU architecture, but is always a power of two, and |
| ... | ... | @@ -1562,9 +1566,9 @@ test "function alignment" { |
| 1562 | 1566 | {#code_end#} |
| 1563 | 1567 | <p> |
| 1564 | 1568 | If you have a pointer or a slice that has a small alignment, but you know that it actually |
| 1565 | | has a bigger alignment, use <a href="#builtin-alignCast">@alignCast</a> to change the |
| 1569 | has a bigger alignment, use {#link|@alignCast#} to change the |
| 1566 | 1570 | pointer into a more aligned pointer. This is a no-op at runtime, but inserts a |
| 1567 | | <a href="#undef-incorrect-pointer-alignment">safety check</a>: |
| 1571 | {#link|safety check|Incorrect Pointer Alignment#}: |
| 1568 | 1572 | </p> |
| 1569 | 1573 | {#code_begin|test_safety|incorrect alignment#} |
| 1570 | 1574 | const assert = @import("std").debug.assert; |
| ... | ... | @@ -1589,7 +1593,7 @@ fn foo(bytes: []u8) -> u32 { |
| 1589 | 1593 | </p> |
| 1590 | 1594 | <p>As an example, this code produces undefined behavior:</p> |
| 1591 | 1595 | <pre><code class="zig">*@ptrCast(&amp;u32, f32(12.34))</code></pre> |
| 1592 | | <p>Instead, use <a href="#builtin-bitCast">@bitCast</a>: |
| 1596 | <p>Instead, use {#link|@bitCast#}: |
| 1593 | 1597 | <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre> |
| 1594 | 1598 | <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p> |
| 1595 | 1599 | {#see_also|Slices|Memory#} |
| ... | ... | @@ -3391,7 +3395,7 @@ test "fibonacci" { |
| 3391 | 3395 | The compiler noticed that evaluating this function at compile-time took a long time, |
| 3392 | 3396 | and thus emitted a compile error and gave up. If the programmer wants to increase |
| 3393 | 3397 | the budget for compile-time computation, they can use a built-in function called |
| 3394 | | <a href="#builtin-setEvalBranchQuota">@setEvalBranchQuota</a> to change the default number 1000 to something else. |
| 3398 | {#link|@setEvalBranchQuota#} to change the default number 1000 to something else. |
| 3395 | 3399 | </p> |
| 3396 | 3400 | <p> |
| 3397 | 3401 | What if we fix the base case, but put the wrong value in the <code>assert</code> line? |
| ... | ... | @@ -3750,7 +3754,7 @@ pub fn main() { |
| 3750 | 3754 | <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code> |
| 3751 | 3755 | except with the alignment adjusted to the new value. |
| 3752 | 3756 | </p> |
| 3753 | | <p>A <a href="#undef-incorrect-pointer-alignment">pointer alignment safety check</a> is added |
| 3757 | <p>A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added |
| 3754 | 3758 | to the generated code to make sure the pointer is aligned as promised.</p> |
| 3755 | 3759 | |
| 3756 | 3760 | {#header_close#} |
| ... | ... | @@ -3767,7 +3771,7 @@ comptime { |
| 3767 | 3771 | }</code></pre> |
| 3768 | 3772 | <p> |
| 3769 | 3773 | The result is a target-specific compile time constant. It is guaranteed to be |
| 3770 | | less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>. |
| 3774 | less than or equal to {#link|@sizeOf(T)|@sizeOf#}. |
| 3771 | 3775 | </p> |
| 3772 | 3776 | {#see_also|Alignment#} |
| 3773 | 3777 | {#header_close#} |
| ... | ... | @@ -4109,7 +4113,7 @@ fn add(a: i32, b: i32) -> i32 { return a + b; } |
| 4109 | 4113 | {#header_open|@intToPtr#} |
| 4110 | 4114 | <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre> |
| 4111 | 4115 | <p> |
| 4112 | | Converts an integer to a pointer. To convert the other way, use <a href="#builtin-ptrToInt">@ptrToInt</a>. |
| 4116 | Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}. |
| 4113 | 4117 | </p> |
| 4114 | 4118 | {#header_close#} |
| 4115 | 4119 | {#header_open|@IntType#} |
| ... | ... | @@ -4286,7 +4290,7 @@ test "call foo" { |
| 4286 | 4290 | <li><code>fn()</code></li> |
| 4287 | 4291 | <li><code>?fn()</code></li> |
| 4288 | 4292 | </ul> |
| 4289 | | <p>To convert the other way, use <a href="#builtin-intToPtr">@intToPtr</a></p> |
| 4293 | <p>To convert the other way, use {#link|@intToPtr#}</p> |
| 4290 | 4294 | |
| 4291 | 4295 | {#header_close#} |
| 4292 | 4296 | {#header_open|@rem#} |
| ... | ... | @@ -4539,9 +4543,9 @@ pub const TypeId = enum { |
| 4539 | 4543 | Zig has three build modes: |
| 4540 | 4544 | </p> |
| 4541 | 4545 | <ul> |
| 4542 | | <li><a href="#build-mode-debug">Debug</a> (default)</li> |
| 4543 | | <li><a href="#build-mode-release-fast">ReleaseFast</a></li> |
| 4544 | | <li><a href="#build-mode-release-safe">ReleaseSafe</a></li> |
| 4546 | <li>{#link|Debug#} (default)</li> |
| 4547 | <li>{#link|ReleaseFast#}</li> |
| 4548 | <li>{#link|ReleaseSafe#}</li> |
| 4545 | 4549 | </ul> |
| 4546 | 4550 | <p> |
| 4547 | 4551 | To add standard build options to a <code>build.zig</code> file: |
| ... | ... | @@ -4592,7 +4596,7 @@ pub fn build(b: &Builder) -> %void { |
| 4592 | 4596 | detected at compile-time, Zig emits an error. Most undefined behavior that |
| 4593 | 4597 | cannot be detected at compile-time can be detected at runtime. In these cases, |
| 4594 | 4598 | Zig has safety checks. Safety checks can be disabled on a per-block basis |
| 4595 | | with <code>@setDebugSafety</code>. The <a href="#build-mode-release-fast">ReleaseFast</a> |
| 4599 | with <code>@setDebugSafety</code>. The {#link|ReleaseFast#} |
| 4596 | 4600 | build mode disables all safety checks in order to facilitate optimizations. |
| 4597 | 4601 | </p> |
| 4598 | 4602 | <p> |