| ... | ... | @@ -77,13 +77,7 @@ Hello, world!</code></pre> |
| 77 | 77 | pub fn main() -&gt; %void { |
| 78 | 78 | warn("Hello, world!\n"); |
| 79 | 79 | }</code></pre> |
| 80 | | <p>See also:</p> |
| 81 | | <ul> |
| 82 | | <li><a href="#values">Values</a></li> |
| 83 | | <li><a href="#builtin-import">@import</a></li> |
| 84 | | <li><a href="#errors">Errors</a></li> |
| 85 | | <li><a href="#root-source-file">Root Source File</a></li> |
| 86 | | </ul> |
| 80 | {#see_also|Values|@import|Errors|Root Source File#} |
| 87 | 81 | {#header_close#} |
| 88 | 82 | {#header_open|Source Encoding#} |
| 89 | 83 | <p>Zig source code is encoded in UTF-8. An invalid UTF-8 byte sequence results in a compile error.</p> |
| ... | ... | @@ -391,13 +385,7 @@ value: 1234</code></pre> |
| 391 | 385 | <td>an error code</td> |
| 392 | 386 | </tr> |
| 393 | 387 | </table> |
| 394 | | <p>See also:</p> |
| 395 | | <ul> |
| 396 | | <li><a href="#integers">Integers</a></li> |
| 397 | | <li><a href="#floats">Floats</a></li> |
| 398 | | <li><a href="#void">void</a></li> |
| 399 | | <li><a href="#errors">Errors</a></li> |
| 400 | | </ul> |
| 388 | {#see_also|Integers|Floats|void|Errors#} |
| 401 | 389 | {#header_close#} |
| 402 | 390 | {#header_open|Primitive Values#} |
| 403 | 391 | <table> |
| ... | ... | @@ -426,11 +414,7 @@ value: 1234</code></pre> |
| 426 | 414 | <td>refers to the thing in immediate scope</td> |
| 427 | 415 | </tr> |
| 428 | 416 | </table> |
| 429 | | <p>See also:</p> |
| 430 | | <ul> |
| 431 | | <li><a href="#nullables">Nullables</a></li> |
| 432 | | <li><a href="#this">this</a></li> |
| 433 | | </ul> |
| 417 | {#see_also|Nullables|this#} |
| 434 | 418 | {#header_close#} |
| 435 | 419 | {#header_open|String Literals#} |
| 436 | 420 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -452,11 +436,7 @@ test "string literals" { |
| 452 | 436 | }</code></pre> |
| 453 | 437 | <pre><code class="sh">$ zig test string_literals.zig |
| 454 | 438 | Test 1/1 string literals...OK</code></pre> |
| 455 | | <p>See also:</p> |
| 456 | | <ul> |
| 457 | | <li><a href="#arrays">Arrays</a></li> |
| 458 | | <li><a href="#zig-test">Zig Test</a></li> |
| 459 | | </ul> |
| 439 | {#see_also|Arrays|Zig Test#} |
| 460 | 440 | {#header_open|Escape Sequences#} |
| 461 | 441 | <table> |
| 462 | 442 | <tr> |
| ... | ... | @@ -538,10 +518,7 @@ Test 1/1 string literals...OK</code></pre> |
| 538 | 518 | In this example the variable <code>c_string_literal</code> has type <code>&amp;const char</code> and |
| 539 | 519 | has a terminating null byte. |
| 540 | 520 | </p> |
| 541 | | <p>See also:</p> |
| 542 | | <ul> |
| 543 | | <li><a href="#builtin-embedFile">@embedFile</a></li> |
| 544 | | </ul> |
| 521 | {#see_also|@embedFile#} |
| 545 | 522 | {#header_close#} |
| 546 | 523 | {#header_close#} |
| 547 | 524 | {#header_open|Assignment#} |
| ... | ... | @@ -627,12 +604,7 @@ const binary_int = 0b11110000;</code></pre> |
| 627 | 604 | integer overflow. Also available are operations such as <code>+%</code> and |
| 628 | 605 | <code>-%</code> which are defined to have wrapping arithmetic on all targets. |
| 629 | 606 | </p> |
| 630 | | <p>See also:</p> |
| 631 | | <ul> |
| 632 | | <li><a href="#undef-integer-overflow">Integer Overflow</a></li> |
| 633 | | <li><a href="#undef-division-by-zero">Division By Zero</a></li> |
| 634 | | <li><a href="#undef-int-overflow-wrap">Wrapping Operations</a></li> |
| 635 | | </ul> |
| 607 | {#see_also|Integer Overflow|Division by Zero|Wrapping Operations#} |
| 636 | 608 | {#header_close#} |
| 637 | 609 | {#header_close#} |
| 638 | 610 | {#header_open|Floats#} |
| ... | ... | @@ -680,11 +652,7 @@ $ zig build-exe test.zig --object foo.o |
| 680 | 652 | $ ./test |
| 681 | 653 | optimized = 1.0e-2 |
| 682 | 654 | strict = 9.765625e-3</code></pre> |
| 683 | | <p>See also:</p> |
| 684 | | <ul> |
| 685 | | <li><a href="#builtin-setFloatMode">@setFloatMode</a></li> |
| 686 | | <li><a href="#undef-division-by-zero">Division By Zero</a></li> |
| 687 | | </ul> |
| 655 | {#see_also|@setFloatMode|Division by Zero#} |
| 688 | 656 | {#header_close#} |
| 689 | 657 | {#header_open|Operators#} |
| 690 | 658 | {#header_open|Table of Operators#} |
| ... | ... | @@ -1402,11 +1370,7 @@ Test 1/4 iterate over an array...OK |
| 1402 | 1370 | Test 2/4 modify an array...OK |
| 1403 | 1371 | Test 3/4 compile-time array initalization...OK |
| 1404 | 1372 | Test 4/4 array initialization with function calls...OK</code></pre> |
| 1405 | | <p>See also:</p> |
| 1406 | | <ul> |
| 1407 | | <li><a href="#for">for</a></li> |
| 1408 | | <li><a href="#slices">Slices</a></li> |
| 1409 | | </ul> |
| 1373 | {#see_also|for|Slices#} |
| 1410 | 1374 | {#header_close#} |
| 1411 | 1375 | {#header_open|Pointers#} |
| 1412 | 1376 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -1659,11 +1623,7 @@ Tests failed. Use the following command to reproduce the failure: |
| 1659 | 1623 | <p>Instead, use <a href="#builtin-bitCast">@bitCast</a>: |
| 1660 | 1624 | <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre> |
| 1661 | 1625 | <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p> |
| 1662 | | <p>See also:</p> |
| 1663 | | <ul> |
| 1664 | | <li><a href="#slices">Slices</a></li> |
| 1665 | | <li><a href="#memory">Memory</a></li> |
| 1666 | | </ul> |
| 1626 | {#see_also|Slices|Memory#} |
| 1667 | 1627 | {#header_close#} |
| 1668 | 1628 | {#header_close#} |
| 1669 | 1629 | {#header_open|Slices#} |
| ... | ... | @@ -1760,12 +1720,7 @@ test "slice widening" { |
| 1760 | 1720 | Test 1/3 using slices for strings...OK |
| 1761 | 1721 | Test 2/3 slice pointer...OK |
| 1762 | 1722 | Test 3/3 slice widening...OK</code></pre> |
| 1763 | | <p>See also:</p> |
| 1764 | | <ul> |
| 1765 | | <li><a href="#pointers">Pointers</a></li> |
| 1766 | | <li><a href="#for">for</a></li> |
| 1767 | | <li><a href="#arrays">Arrays</a></li> |
| 1768 | | </ul> |
| 1723 | {#see_also|Pointers|for|Arrays#} |
| 1769 | 1724 | {#header_close#} |
| 1770 | 1725 | {#header_open|struct#} |
| 1771 | 1726 | <pre><code class="zig">// Declare a struct. |
| ... | ... | @@ -1907,11 +1862,7 @@ Test 1/4 dot product...OK |
| 1907 | 1862 | Test 2/4 struct namespaced variable...OK |
| 1908 | 1863 | Test 3/4 field parent pointer...OK |
| 1909 | 1864 | Test 4/4 linked list...OK</code></pre> |
| 1910 | | <p>See also:</p> |
| 1911 | | <ul> |
| 1912 | | <li><a href="#comptime">comptime</a></li> |
| 1913 | | <li><a href="#builtin-fieldParentPtr">@fieldParentPtr</a></li> |
| 1914 | | </ul> |
| 1865 | {#see_also|comptime|@fieldParentPtr#} |
| 1915 | 1866 | {#header_close#} |
| 1916 | 1867 | {#header_open|enum#} |
| 1917 | 1868 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -2024,12 +1975,7 @@ Test 5/8 @TagType...OK |
| 2024 | 1975 | Test 6/8 @memberCount...OK |
| 2025 | 1976 | Test 7/8 @memberName...OK |
| 2026 | 1977 | Test 8/8 @tagName...OK</code></pre> |
| 2027 | | <p>See also:</p> |
| 2028 | | <ul> |
| 2029 | | <li><a href="#builtin-memberName">@memberName</a></li> |
| 2030 | | <li><a href="#builtin-memberCount">@memberCount</a></li> |
| 2031 | | <li><a href="#builtin-tagName">@tagName</a></li> |
| 2032 | | </ul> |
| 1978 | {#see_also|@memberName|@memberCount|@tagName#} |
| 2033 | 1979 | {#header_close#} |
| 2034 | 1980 | {#header_open|union#} |
| 2035 | 1981 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -2235,13 +2181,7 @@ test "switch inside function" { |
| 2235 | 2181 | Test 1/2 switch simple...OK |
| 2236 | 2182 | Test 2/2 switch enum...OK |
| 2237 | 2183 | Test 3/3 switch inside function...OK</code></pre> |
| 2238 | | <p>See also:</p> |
| 2239 | | <ul> |
| 2240 | | <li><a href="#comptime">comptime</a></li> |
| 2241 | | <li><a href="#enum">enum</a></li> |
| 2242 | | <li><a href="#builtin-compileError">@compileError</a></li> |
| 2243 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 2244 | | </ul> |
| 2184 | {#see_also|comptime|enum|@compileError|Compile Variables#} |
| 2245 | 2185 | {#header_close#} |
| 2246 | 2186 | {#header_open|while#} |
| 2247 | 2187 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -2404,14 +2344,7 @@ Test 5/8 while loop continuation expression, more complicated...OK |
| 2404 | 2344 | Test 6/8 while else...OK |
| 2405 | 2345 | Test 7/8 while null capture...OK |
| 2406 | 2346 | Test 8/8 inline while loop...OK</code></pre> |
| 2407 | | <p>See also:</p> |
| 2408 | | <ul> |
| 2409 | | <li><a href="#if">if</a></li> |
| 2410 | | <li><a href="#nullables">Nullables</a></li> |
| 2411 | | <li><a href="#errors">Errors</a></li> |
| 2412 | | <li><a href="#comptime">comptime</a></li> |
| 2413 | | <li><a href="#unreachable">unreachable</a></li> |
| 2414 | | </ul> |
| 2347 | {#see_also|if|Nullables|Errors|comptime|unreachable#} |
| 2415 | 2348 | {#header_close#} |
| 2416 | 2349 | {#header_open|for#} |
| 2417 | 2350 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| ... | ... | @@ -2507,13 +2440,7 @@ Test 1/4 for basics...OK |
| 2507 | 2440 | Test 2/4 for reference...OK |
| 2508 | 2441 | Test 3/4 for else...OK |
| 2509 | 2442 | Test 4/4 inline for loop...OK</code></pre> |
| 2510 | | <p>See also:</p> |
| 2511 | | <ul> |
| 2512 | | <li><a href="#while">while</a></li> |
| 2513 | | <li><a href="#comptime">comptime</a></li> |
| 2514 | | <li><a href="#arrays">Arrays</a></li> |
| 2515 | | <li><a href="#slices">Slices</a></li> |
| 2516 | | </ul> |
| 2443 | {#see_also|while|comptime|Arrays|Slices#} |
| 2517 | 2444 | {#header_close#} |
| 2518 | 2445 | {#header_open|if#} |
| 2519 | 2446 | <pre><code class="zig">// If expressions have three uses, corresponding to the three types: |
| ... | ... | @@ -2628,29 +2555,9 @@ test "if error union" { |
| 2628 | 2555 | Test 1/3 if boolean...OK |
| 2629 | 2556 | Test 2/3 if nullable...OK |
| 2630 | 2557 | Test 3/3 if error union...OK</code></pre> |
| 2631 | | <p>See also:</p> |
| 2632 | | <ul> |
| 2633 | | <li><a href="#nullables">Nullables</a></li> |
| 2634 | | <li><a href="#errors">Errors</a></li> |
| 2635 | | </ul> |
| 2558 | {#see_also|Nullables|Errors#} |
| 2636 | 2559 | {#header_close#} |
| 2637 | | {#header_open|goto#} |
| 2638 | | <pre><code class="zig">const assert = @import("std").debug.assert; |
| 2639 | | |
| 2640 | | test "goto" { |
| 2641 | | var value = false; |
| 2642 | | goto label; |
| 2643 | | value = true; |
| 2644 | | |
| 2645 | | label: |
| 2646 | | assert(value == false); |
| 2647 | | } |
| 2648 | | </code></pre> |
| 2649 | | <pre><code class="sh">$ zig test goto.zig |
| 2650 | | Test 1/1 goto...OK |
| 2651 | | </code></pre> |
| 2652 | | <p>Note that there are <a href="https://github.com/zig-lang/zig/issues/346">plans to remove goto</a></p> |
| 2653 | | {{deheader_open:fer}} |
| 2560 | {#header_open|defer#} |
| 2654 | 2561 | <pre><code class="zig">const assert = @import("std").debug.assert; |
| 2655 | 2562 | const printf = @import("std").io.stdout.printf; |
| 2656 | 2563 | |
| ... | ... | @@ -2736,10 +2643,7 @@ encountered an error! |
| 2736 | 2643 | end of function |
| 2737 | 2644 | OK |
| 2738 | 2645 | </code></pre> |
| 2739 | | <p>See also:</p> |
| 2740 | | <ul> |
| 2741 | | <li><a href="#errors">Errors</a></li> |
| 2742 | | </ul> |
| 2646 | {#see_also|Errors#} |
| 2743 | 2647 | {#header_close#} |
| 2744 | 2648 | {#header_open|unreachable#} |
| 2745 | 2649 | <p> |
| ... | ... | @@ -2811,12 +2715,7 @@ comptime { |
| 2811 | 2715 | test.zig:9:12: error: unreachable code |
| 2812 | 2716 | assert(@typeOf(unreachable) == noreturn); |
| 2813 | 2717 | ^</code></pre> |
| 2814 | | <p>See also:</p> |
| 2815 | | <ul> |
| 2816 | | <li><a href="#zig-test">Zig Test</a></li> |
| 2817 | | <li><a href="#build-mode">Build Mode</a></li> |
| 2818 | | <li><a href="#comptime">comptime</a></li> |
| 2819 | | </ul> |
| 2718 | {#see_also|Zig Test|Build Mode|comptime#} |
| 2820 | 2719 | {#header_close#} |
| 2821 | 2720 | {#header_close#} |
| 2822 | 2721 | {#header_open|noreturn#} |
| ... | ... | @@ -3142,12 +3041,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 { |
| 3142 | 3041 | in other languages. |
| 3143 | 3042 | </li> |
| 3144 | 3043 | </ul> |
| 3145 | | <p>See also:</p> |
| 3146 | | <ul> |
| 3147 | | <li><a href="#defer">defer</a></li> |
| 3148 | | <li><a href="#if">if</a></li> |
| 3149 | | <li><a href="#switch">switch</a></li> |
| 3150 | | </ul> |
| 3044 | {#see_also|defer|if|switch#} |
| 3151 | 3045 | {#header_close#} |
| 3152 | 3046 | {#header_open|Nullables#} |
| 3153 | 3047 | <p> |
| ... | ... | @@ -3976,11 +3870,7 @@ comptime { |
| 3976 | 3870 | The result is a target-specific compile time constant. It is guaranteed to be |
| 3977 | 3871 | less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>. |
| 3978 | 3872 | </p> |
| 3979 | | <p>See also:</p> |
| 3980 | | <ul> |
| 3981 | | <li><a href="#alignment">Alignment</a></li> |
| 3982 | | </ul> |
| 3983 | | |
| 3873 | {#see_also|Alignment#} |
| 3984 | 3874 | {#header_close#} |
| 3985 | 3875 | {#header_open|@cDefine#} |
| 3986 | 3876 | <pre><code class="zig">@cDefine(comptime name: []u8, value)</code></pre> |
| ... | ... | @@ -3999,14 +3889,7 @@ comptime { |
| 3999 | 3889 | Use the void value, like this: |
| 4000 | 3890 | </p> |
| 4001 | 3891 | <pre><code class="zig">@cDefine("_GNU_SOURCE", {})</code></pre> |
| 4002 | | <p>See also:</p> |
| 4003 | | <ul> |
| 4004 | | <li><a href="#c-import">Import from C Header File</a></li> |
| 4005 | | <li><a href="#builtin-cInclude">@cInclude</a></li> |
| 4006 | | <li><a href="#builtin-cImport">@cImport</a></li> |
| 4007 | | <li><a href="#builtin-cUndef">@cUndef</a></li> |
| 4008 | | <li><a href="#void">void</a></li> |
| 4009 | | </ul> |
| 3892 | {#see_also|Import from C Header File|@cInclude|@cImport|@cUndef|void#} |
| 4010 | 3893 | {#header_close#} |
| 4011 | 3894 | {#header_open|@cImport#} |
| 4012 | 3895 | <pre><code class="zig">@cImport(expression) -&gt; (namespace)</code></pre> |
| ... | ... | @@ -4019,13 +3902,7 @@ comptime { |
| 4019 | 3902 | <code>@cInclude</code>, <code>@cDefine</code>, and <code>@cUndef</code> work |
| 4020 | 3903 | within this expression, appending to a temporary buffer which is then parsed as C code. |
| 4021 | 3904 | </p> |
| 4022 | | <p>See also:</p> |
| 4023 | | <ul> |
| 4024 | | <li><a href="#c-import">Import from C Header File</a></li> |
| 4025 | | <li><a href="#builtin-cInclude">@cInclude</a></li> |
| 4026 | | <li><a href="#builtin-cDefine">@cDefine</a></li> |
| 4027 | | <li><a href="#builtin-cUndef">@cUndef</a></li> |
| 4028 | | </ul> |
| 3905 | {#see_also|Import from C Header File|@cInclude|@cDefine|@cUndef#} |
| 4029 | 3906 | {#header_close#} |
| 4030 | 3907 | {#header_open|@cInclude#} |
| 4031 | 3908 | <pre><code class="zig">@cInclude(comptime path: []u8)</code></pre> |
| ... | ... | @@ -4036,13 +3913,7 @@ comptime { |
| 4036 | 3913 | This appends <code>#include <$path>\n</code> to the <code>c_import</code> |
| 4037 | 3914 | temporary buffer. |
| 4038 | 3915 | </p> |
| 4039 | | <p>See also:</p> |
| 4040 | | <ul> |
| 4041 | | <li><a href="#c-import">Import from C Header File</a></li> |
| 4042 | | <li><a href="#builtin-cImport">@cImport</a></li> |
| 4043 | | <li><a href="#builtin-cDefine">@cDefine</a></li> |
| 4044 | | <li><a href="#builtin-cUndef">@cUndef</a></li> |
| 4045 | | </ul> |
| 3916 | {#see_also|Import from C Header File|@cImport|@cDefine|@cUndef#} |
| 4046 | 3917 | {#header_close#} |
| 4047 | 3918 | {#header_open|@cUndef#} |
| 4048 | 3919 | <pre><code class="zig">@cUndef(comptime name: []u8)</code></pre> |
| ... | ... | @@ -4053,13 +3924,7 @@ comptime { |
| 4053 | 3924 | This appends <code>#undef $name</code> to the <code>@cImport</code> |
| 4054 | 3925 | temporary buffer. |
| 4055 | 3926 | </p> |
| 4056 | | <p>See also:</p> |
| 4057 | | <ul> |
| 4058 | | <li><a href="#c-import">Import from C Header File</a></li> |
| 4059 | | <li><a href="#builtin-cImport">@cImport</a></li> |
| 4060 | | <li><a href="#builtin-cDefine">@cDefine</a></li> |
| 4061 | | <li><a href="#builtin-cInclude">@cInclude</a></li> |
| 4062 | | </ul> |
| 3927 | {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#} |
| 4063 | 3928 | {#header_close#} |
| 4064 | 3929 | {#header_open|@canImplicitCast#} |
| 4065 | 3930 | <pre><code class="zig">@canImplicitCast(comptime T: type, value) -&gt; bool</code></pre> |
| ... | ... | @@ -4091,11 +3956,7 @@ comptime { |
| 4091 | 3956 | <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>. |
| 4092 | 3957 | </p> |
| 4093 | 3958 | <p><code>@typeOf(ptr).alignment</code> must be <code>&gt;= @sizeOf(T).</code></p> |
| 4094 | | <p>See also:</p> |
| 4095 | | <ul> |
| 4096 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 4097 | | </ul> |
| 4098 | | |
| 3959 | {#see_also|Compile Variables#} |
| 4099 | 3960 | {#header_close#} |
| 4100 | 3961 | {#header_open|@compileError#} |
| 4101 | 3962 | <pre><code class="zig">@compileError(comptime msg: []u8)</code></pre> |
| ... | ... | @@ -4183,12 +4044,8 @@ test.zig:6:2: error: found compile log statement |
| 4183 | 4044 | <li><code>@divExact(6, 3) == 2</code></li> |
| 4184 | 4045 | <li><code>@divExact(a, b) * b == a</code></li> |
| 4185 | 4046 | </ul> |
| 4186 | | <p>See also:</p> |
| 4187 | | <ul> |
| 4188 | | <li><a href="#builtin-divTrunc">@divTrunc</a></li> |
| 4189 | | <li><a href="#builtin-divFloor">@divFloor</a></li> |
| 4190 | | <li><code>@import("std").math.divExact</code></li> |
| 4191 | | </ul> |
| 4047 | <p>For a function that returns a possible error code, use <code>@import("std").math.divExact</code>.</p> |
| 4048 | {#see_also|@divTrunc|@divFloor#} |
| 4192 | 4049 | {#header_close#} |
| 4193 | 4050 | {#header_open|@divFloor#} |
| 4194 | 4051 | <pre><code class="zig">@divFloor(numerator: T, denominator: T) -&gt; T</code></pre> |
| ... | ... | @@ -4201,12 +4058,8 @@ test.zig:6:2: error: found compile log statement |
| 4201 | 4058 | <li><code>@divFloor(-5, 3) == -2</code></li> |
| 4202 | 4059 | <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li> |
| 4203 | 4060 | </ul> |
| 4204 | | <p>See also:</p> |
| 4205 | | <ul> |
| 4206 | | <li><a href="#builtin-divTrunc">@divTrunc</a></li> |
| 4207 | | <li><a href="#builtin-divExact">@divExact</a></li> |
| 4208 | | <li><code>@import("std").math.divFloor</code></li> |
| 4209 | | </ul> |
| 4061 | <p>For a function that returns a possible error code, use <code>@import("std").math.divFloor</code>.</p> |
| 4062 | {#see_also|@divTrunc|@divExact#} |
| 4210 | 4063 | {#header_close#} |
| 4211 | 4064 | {#header_open|@divTrunc#} |
| 4212 | 4065 | <pre><code class="zig">@divTrunc(numerator: T, denominator: T) -&gt; T</code></pre> |
| ... | ... | @@ -4219,12 +4072,8 @@ test.zig:6:2: error: found compile log statement |
| 4219 | 4072 | <li><code>@divTrunc(-5, 3) == -1</code></li> |
| 4220 | 4073 | <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li> |
| 4221 | 4074 | </ul> |
| 4222 | | <p>See also:</p> |
| 4223 | | <ul> |
| 4224 | | <li><a href="#builtin-divFloor">@divFloor</a></li> |
| 4225 | | <li><a href="#builtin-divExact">@divExact</a></li> |
| 4226 | | <li><code>@import("std").math.divTrunc</code></li> |
| 4227 | | </ul> |
| 4075 | <p>For a function that returns a possible error code, use <code>@import("std").math.divTrunc</code>.</p> |
| 4076 | {#see_also|@divFloor|@divExact#} |
| 4228 | 4077 | {#header_close#} |
| 4229 | 4078 | {#header_open|@embedFile#} |
| 4230 | 4079 | <pre><code class="zig">@embedFile(comptime path: []const u8) -&gt; [X]u8</code></pre> |
| ... | ... | @@ -4236,10 +4085,7 @@ test.zig:6:2: error: found compile log statement |
| 4236 | 4085 | <p> |
| 4237 | 4086 | <code>path</code> is absolute or relative to the current file, just like <code>@import</code>. |
| 4238 | 4087 | </p> |
| 4239 | | <p>See also:</p> |
| 4240 | | <ul> |
| 4241 | | <li><a href="#builtin-import">@import</a></li> |
| 4242 | | </ul> |
| 4088 | {#see_also|@import#} |
| 4243 | 4089 | {#header_close#} |
| 4244 | 4090 | {#header_open|@export#} |
| 4245 | 4091 | <pre><code class="zig">@export(comptime name: []const u8, target: var, linkage: builtin.GlobalLinkage) -&gt; []const u8</code></pre> |
| ... | ... | @@ -4294,10 +4140,7 @@ test.zig:6:2: error: found compile log statement |
| 4294 | 4140 | <p> |
| 4295 | 4141 | <code>AtomicOrder</code> can be found with <code>@import("builtin").AtomicOrder</code>. |
| 4296 | 4142 | </p> |
| 4297 | | <p>See also:</p> |
| 4298 | | <ul> |
| 4299 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 4300 | | </ul> |
| 4143 | {#see_also|Compile Variables#} |
| 4301 | 4144 | {#header_close#} |
| 4302 | 4145 | {#header_open|@fieldParentPtr#} |
| 4303 | 4146 | <pre><code class="zig">@fieldParentPtr(comptime ParentType: type, comptime field_name: []const u8, |
| ... | ... | @@ -4338,11 +4181,7 @@ test.zig:6:2: error: found compile log statement |
| 4338 | 4181 | <li><code>@import("std")</code> - Zig Standard Library</li> |
| 4339 | 4182 | <li><code>@import("builtin")</code> - Compiler-provided types and variables</li> |
| 4340 | 4183 | </ul> |
| 4341 | | <p>See also:</p> |
| 4342 | | <ul> |
| 4343 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 4344 | | <li><a href="#builtin-embedFile">@embedFile</a></li> |
| 4345 | | </ul> |
| 4184 | {#see_also|Compile Variables|@embedFile#} |
| 4346 | 4185 | {#header_close#} |
| 4347 | 4186 | {#header_open|@inlineCall#} |
| 4348 | 4187 | <pre><code class="zig">@inlineCall(function: X, args: ...) -&gt; Y</code></pre> |
| ... | ... | @@ -4359,10 +4198,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre> |
| 4359 | 4198 | Unlike a normal function call, however, <code>@inlineCall</code> guarantees that the call |
| 4360 | 4199 | will be inlined. If the call cannot be inlined, a compile error is emitted. |
| 4361 | 4200 | </p> |
| 4362 | | <p>See also:</p> |
| 4363 | | <ul> |
| 4364 | | <li><a href="#builtin-noInlineCall">@noInlineCall</a></li> |
| 4365 | | </ul> |
| 4201 | {#see_also|@noInlineCall#} |
| 4366 | 4202 | {#header_close#} |
| 4367 | 4203 | {#header_open|@intToPtr#} |
| 4368 | 4204 | <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre> |
| ... | ... | @@ -4454,11 +4290,8 @@ mem.set(u8, dest, c);</code></pre> |
| 4454 | 4290 | <li><code>@mod(-5, 3) == 1</code></li> |
| 4455 | 4291 | <li><code>@divFloor(a, b) + @mod(a, b) == a</code></li> |
| 4456 | 4292 | </ul> |
| 4457 | | <p>See also:</p> |
| 4458 | | <ul> |
| 4459 | | <li><a href="#builtin-rem">@rem</a></li> |
| 4460 | | <li><code>@import("std").math.mod</code></li> |
| 4461 | | </ul> |
| 4293 | <p>For a function that returns an error code, see <code>@import("std").math.mod</code>.</p> |
| 4294 | {#see_also|@rem#} |
| 4462 | 4295 | {#header_close#} |
| 4463 | 4296 | {#header_open|@mulWithOverflow#} |
| 4464 | 4297 | <pre><code class="zig">@mulWithOverflow(comptime T: type, a: T, b: T, result: &amp;T) -&gt; bool</code></pre> |
| ... | ... | @@ -4483,10 +4316,7 @@ fn add(a: i32, b: i32) -&gt; i32 { a + b }</code></pre> |
| 4483 | 4316 | Unlike a normal function call, however, <code>@noInlineCall</code> guarantees that the call |
| 4484 | 4317 | will not be inlined. If the call must be inlined, a compile error is emitted. |
| 4485 | 4318 | </p> |
| 4486 | | <p>See also:</p> |
| 4487 | | <ul> |
| 4488 | | <li><a href="#builtin-inlineCall">@inlineCall</a></li> |
| 4489 | | </ul> |
| 4319 | {#see_also|@inlineCall#} |
| 4490 | 4320 | {#header_close#} |
| 4491 | 4321 | {#header_open|@offsetOf#} |
| 4492 | 4322 | <pre><code class="zig">@offsetOf(comptime T: type, comptime field_name: [] const u8) -&gt; (number literal)</code></pre> |
| ... | ... | @@ -4529,11 +4359,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4529 | 4359 | <li>From library code, calling the programmer's panic function if they exposed one in the root source file.</li> |
| 4530 | 4360 | <li>When mixing C and Zig code, calling the canonical panic implementation across multiple .o files.</li> |
| 4531 | 4361 | </ul> |
| 4532 | | <p>See also:</p> |
| 4533 | | <ul> |
| 4534 | | <li><a href="#root-source-file">Root Source File</a></li> |
| 4535 | | </ul> |
| 4536 | | |
| 4362 | {#see_also|Root Source File#} |
| 4537 | 4363 | {#header_close#} |
| 4538 | 4364 | {#header_open|@ptrCast#} |
| 4539 | 4365 | <pre><code class="zig">@ptrCast(comptime DestType: type, value: var) -&gt; DestType</code></pre> |
| ... | ... | @@ -4565,11 +4391,8 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4565 | 4391 | <li><code>@rem(-5, 3) == -2</code></li> |
| 4566 | 4392 | <li><code>@divTrunc(a, b) + @rem(a, b) == a</code></li> |
| 4567 | 4393 | </ul> |
| 4568 | | <p>See also:</p> |
| 4569 | | <ul> |
| 4570 | | <li><a href="#builtin-mod">@mod</a></li> |
| 4571 | | <li><code>@import("std").math.rem</code></li> |
| 4572 | | </ul> |
| 4394 | <p>For a function that returns an error code, see <code>@import("std").math.rem</code>.</p> |
| 4395 | {#see_also|@mod#} |
| 4573 | 4396 | {#header_close#} |
| 4574 | 4397 | {#header_open|@returnAddress#} |
| 4575 | 4398 | <pre><code class="zig">@returnAddress()</code></pre> |
| ... | ... | @@ -4584,7 +4407,6 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4584 | 4407 | <p> |
| 4585 | 4408 | This function is only valid within function scope. |
| 4586 | 4409 | </p> |
| 4587 | | |
| 4588 | 4410 | {#header_close#} |
| 4589 | 4411 | {#header_open|@setDebugSafety#} |
| 4590 | 4412 | <pre><code class="zig">@setDebugSafety(scope, safety_on: bool)</code></pre> |
| ... | ... | @@ -4623,11 +4445,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4623 | 4445 | <pre><code class="sh">$ ./zig build-obj test.zig</code></pre> |
| 4624 | 4446 | <p>(no output because it worked fine)</p> |
| 4625 | 4447 | |
| 4626 | | <p>See also:</p> |
| 4627 | | <ul> |
| 4628 | | <li><a href="#comptime">comptime</a></li> |
| 4629 | | </ul> |
| 4630 | | |
| 4448 | {#see_also|comptime#} |
| 4631 | 4449 | {#header_close#} |
| 4632 | 4450 | {#header_open|@setFloatMode#} |
| 4633 | 4451 | <pre><code class="zig">@setFloatMode(scope, mode: @import("builtin").FloatMode)</code></pre> |
| ... | ... | @@ -4655,21 +4473,14 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4655 | 4473 | <code>Strict</code> - Floating point operations follow strict IEEE compliance. |
| 4656 | 4474 | </li> |
| 4657 | 4475 | </ul> |
| 4658 | | <p>See also:</p> |
| 4659 | | <ul> |
| 4660 | | <li><a href="#float-operations">Floating Point Operations</a></li> |
| 4661 | | </ul> |
| 4662 | | |
| 4476 | {#see_also|Floating Point Operations#} |
| 4663 | 4477 | {#header_close#} |
| 4664 | 4478 | {#header_open|@setGlobalLinkage#} |
| 4665 | 4479 | <pre><code class="zig">@setGlobalLinkage(global_variable_name, comptime linkage: GlobalLinkage)</code></pre> |
| 4666 | 4480 | <p> |
| 4667 | 4481 | <code>GlobalLinkage</code> can be found with <code>@import("builtin").GlobalLinkage</code>. |
| 4668 | 4482 | </p> |
| 4669 | | <p>See also:</p> |
| 4670 | | <ul> |
| 4671 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 4672 | | </ul> |
| 4483 | {#see_also|Compile Variables#} |
| 4673 | 4484 | {#header_close#} |
| 4674 | 4485 | {#header_open|@setGlobalSection#} |
| 4675 | 4486 | <pre><code class="zig">@setGlobalSection(global_variable_name, comptime section_name: []const u8) -&gt; bool</code></pre> |
| ... | ... | @@ -4687,11 +4498,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4687 | 4498 | The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits. |
| 4688 | 4499 | This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior. |
| 4689 | 4500 | </p> |
| 4690 | | <p>See also:</p> |
| 4691 | | <ul> |
| 4692 | | <li><a href="#builtin-shrExact">@shrExact</a></li> |
| 4693 | | <li><a href="#builtin-shlWithOverflow">@shlWithOverflow</a></li> |
| 4694 | | </ul> |
| 4501 | {#see_also|@shrExact|@shlWithOverflow#} |
| 4695 | 4502 | {#header_close#} |
| 4696 | 4503 | {#header_open|@shlWithOverflow#} |
| 4697 | 4504 | <pre><code class="zig">@shlWithOverflow(comptime T: type, a: T, shift_amt: Log2T, result: &amp;T) -&gt; bool</code></pre> |
| ... | ... | @@ -4704,11 +4511,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4704 | 4511 | The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits. |
| 4705 | 4512 | This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior. |
| 4706 | 4513 | </p> |
| 4707 | | <p>See also:</p> |
| 4708 | | <ul> |
| 4709 | | <li><a href="#builtin-shlExact">@shlExact</a></li> |
| 4710 | | <li><a href="#builtin-shrExact">@shrExact</a></li> |
| 4711 | | </ul> |
| 4514 | {#see_also|@shlExact|@shrExact#} |
| 4712 | 4515 | {#header_close#} |
| 4713 | 4516 | {#header_open|@shrExact#} |
| 4714 | 4517 | <pre><code class="zig">@shrExact(value: T, shift_amt: Log2T) -&gt; T</code></pre> |
| ... | ... | @@ -4720,10 +4523,7 @@ test.zig:5:9: error: expected type '&amp;Derp', found '&amp;Wat' |
| 4720 | 4523 | The type of <code>shift_amt</code> is an unsigned integer with <code>log2(T.bit_count)</code> bits. |
| 4721 | 4524 | This is because <code>shift_amt &gt;= T.bit_count</code> is undefined behavior. |
| 4722 | 4525 | </p> |
| 4723 | | <p>See also:</p> |
| 4724 | | <ul> |
| 4725 | | <li><a href="#builtin-shlExact">@shlExact</a></li> |
| 4726 | | </ul> |
| 4526 | {#see_also|@shlExact|@shlWithOverflow#} |
| 4727 | 4527 | {#header_close#} |
| 4728 | 4528 | {#header_open|@sizeOf#} |
| 4729 | 4529 | <pre><code class="zig">@sizeOf(comptime T: type) -&gt; (number literal)</code></pre> |
| ... | ... | @@ -4863,12 +4663,7 @@ pub fn build(b: &amp;Builder) { |
| 4863 | 4663 | <li>Safety checks enabled</li> |
| 4864 | 4664 | <li>Slow compilation speed</li> |
| 4865 | 4665 | </ul> |
| 4866 | | <p>See also:</p> |
| 4867 | | <ul> |
| 4868 | | <li><a href="#compile-variables">Compile Variables</a></li> |
| 4869 | | <li><a href="#zig-build-system">Zig Build System</a></li> |
| 4870 | | <li><a href="#undefined-behavior">Undefined Behavior</a></li> |
| 4871 | | </ul> |
| 4666 | {#see_also|Compile Variables|Zig Build System|Undefined Behavior#} |
| 4872 | 4667 | {#header_close#} |
| 4873 | 4668 | {#header_close#} |
| 4874 | 4669 | {#header_open|Undefined Behavior#} |
| ... | ... | @@ -5234,10 +5029,7 @@ comptime { |
| 5234 | 5029 | <p>TODO: importance of checking for allocation failure</p> |
| 5235 | 5030 | <p>TODO: mention overcommit and the OOM Killer</p> |
| 5236 | 5031 | <p>TODO: mention recursion</p> |
| 5237 | | <p>See also:</p> |
| 5238 | | <ul> |
| 5239 | | <li><a href="#pointers">Pointers</a></li> |
| 5240 | | </ul> |
| 5032 | {#see_also|Pointers#} |
| 5241 | 5033 | |
| 5242 | 5034 | {#header_close#} |
| 5243 | 5035 | {#header_open|Compile Variables#} |
| ... | ... | @@ -5406,10 +5198,7 @@ pub const object_format = ObjectFormat.elf; |
| 5406 | 5198 | pub const mode = Mode.ReleaseFast; |
| 5407 | 5199 | pub const link_libs = [][]const u8 { |
| 5408 | 5200 | };</code></pre> |
| 5409 | | <p>See also:</p> |
| 5410 | | <ul> |
| 5411 | | <li><a href="#build-mode">Build Mode</a></li> |
| 5412 | | </ul> |
| 5201 | {#see_also|Build Mode#} |
| 5413 | 5202 | {#header_close#} |
| 5414 | 5203 | {#header_open|Root Source File#} |
| 5415 | 5204 | <p>TODO: explain how root source file finds other files</p> |
| ... | ... | @@ -5456,10 +5245,7 @@ pub const link_libs = [][]const u8 { |
| 5456 | 5245 | <li><code>c_longdouble</code></li> |
| 5457 | 5246 | <li><code>c_void</code></li> |
| 5458 | 5247 | </ul> |
| 5459 | | <p>See also:</p> |
| 5460 | | <ul> |
| 5461 | | <li><a href="#primitive-types">Primitive Types</a></li> |
| 5462 | | </ul> |
| 5248 | {#see_also|Primitive Types#} |
| 5463 | 5249 | {#header_close#} |
| 5464 | 5250 | {#header_open|C String Literals#} |
| 5465 | 5251 | <pre><code class="zig">extern fn puts(&amp;const u8); |
| ... | ... | @@ -5472,10 +5258,7 @@ pub fn main() -&gt; %void { |
| 5472 | 5258 | c\\multiline C string literal |
| 5473 | 5259 | ); |
| 5474 | 5260 | }</code></pre> |
| 5475 | | <p>See also:</p> |
| 5476 | | <ul> |
| 5477 | | <li><a href="#string-literals">String Literals</a></li> |
| 5478 | | </ul> |
| 5261 | {#see_also|String Literals#} |
| 5479 | 5262 | {#header_close#} |
| 5480 | 5263 | {#header_open|Import from C Header File#} |
| 5481 | 5264 | <p> |
| ... | ... | @@ -5504,14 +5287,7 @@ const c = @cImport({ |
| 5504 | 5287 | } |
| 5505 | 5288 | @cInclude("soundio.h"); |
| 5506 | 5289 | });</code></pre> |
| 5507 | | <p>See also:</p> |
| 5508 | | <ul> |
| 5509 | | <li><a href="#builtin-cImport">@cImport</a></li> |
| 5510 | | <li><a href="#builtin-cInclude">@cInclude</a></li> |
| 5511 | | <li><a href="#builtin-cDefine">@cDefine</a></li> |
| 5512 | | <li><a href="#builtin-cUndef">@cUndef</a></li> |
| 5513 | | <li><a href="#builtin-import">@import</a></li> |
| 5514 | | </ul> |
| 5290 | {#see_also|@cImport|@cInclude|@cDefine|@cUndef|@import#} |
| 5515 | 5291 | {#header_close#} |
| 5516 | 5292 | {#header_open|Mixing Object Files#} |
| 5517 | 5293 | <p> |
| ... | ... | @@ -5571,11 +5347,7 @@ pub fn build(b: &amp;Builder) { |
| 5571 | 5347 | <pre><code class="sh">$ zig build |
| 5572 | 5348 | $ ./test |
| 5573 | 5349 | all your base are belong to us</code></pre> |
| 5574 | | <p>See also:</p> |
| 5575 | | <ul> |
| 5576 | | <li><a href="#targets">Targets</a></li> |
| 5577 | | <li><a href="#zig-build-system">Zig Build System</a></li> |
| 5578 | | </ul> |
| 5350 | {#see_also|Targets|Zig Build System#} |
| 5579 | 5351 | {#header_close#} |
| 5580 | 5352 | {#header_close#} |
| 5581 | 5353 | {#header_open|Targets#} |