| ... | ... | @@ -10802,6 +10802,33 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke |
| 10802 | 10802 | <p>{#syntax#}ptr_to_struct_array[index].struct_member{#endsyntax#}</p> |
| 10803 | 10803 | {#header_close#} |
| 10804 | 10804 | |
| 10805 | {#header_open|C Variadic Functions#} |
| 10806 | <p>Zig supports extern variadic functions.</p> |
| 10807 | {#code_begin|test|variadic_function#} |
| 10808 | {#link_libc#} |
| 10809 | {#code_verbose_cimport#} |
| 10810 | const std = @import("std"); |
| 10811 | const testing = std.testing; |
| 10812 | |
| 10813 | pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; |
| 10814 | |
| 10815 | test "variadic function" { |
| 10816 | try testing.expect(printf("Hello, world!\n") == 14); |
| 10817 | try testing.expect(@typeInfo(@TypeOf(printf)).Fn.is_var_args); |
| 10818 | } |
| 10819 | {#code_end#} |
| 10820 | <p> |
| 10821 | Non extern variadic functions are currently not implemented, but there |
| 10822 | is an accepted proposal. See <a href="https://github.com/ziglang/zig/issues/515">#515</a>. |
| 10823 | </p> |
| 10824 | {#code_begin|obj_err|non-extern function is variadic#} |
| 10825 | export fn printf(format: [*:0]const u8, ...) c_int { |
| 10826 | _ = format; |
| 10827 | |
| 10828 | return 0; |
| 10829 | } |
| 10830 | {#code_end#} |
| 10831 | {#header_close#} |
| 10805 | 10832 | {#header_open|Exporting a C Library#} |
| 10806 | 10833 | <p> |
| 10807 | 10834 | One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages |