File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -10792,6 +10792,33 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
10792
10792
<p>{#syntax#}ptr_to_struct_array[index].struct_member{#endsyntax#}</p>
10793
10793
{#header_close#}
10794
10794
10795
+ {#header_open|C Variadic Functions#}
10796
+ <p>Zig supports extern variadic functions.</p>
10797
+ {#code_begin|test|variadic_function#}
10798
+ {#link_libc#}
10799
+ {#code_verbose_cimport#}
10800
+ const std = @import("std");
10801
+ const testing = std.testing;
10802
+
10803
+ pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
10804
+
10805
+ test "variadic function" {
10806
+ try testing.expect(printf("Hello, world!\n") == 14);
10807
+ try testing.expect(@typeInfo(@TypeOf(printf)).Fn.is_var_args);
10808
+ }
10809
+ {#code_end#}
10810
+ <p>
10811
+ Non extern variadic functions are currently not implemented, but there
10812
+ is an accepted proposal. See <a href="https://github.com/ziglang/zig/issues/515">#515</a>.
10813
+ </p>
10814
+ {#code_begin|obj_err|non-extern function is variadic#}
10815
+ export fn printf(format: [*:0]const u8, ...) c_int {
10816
+ _ = format;
10817
+
10818
+ return 0;
10819
+ }
10820
+ {#code_end#}
10821
+ {#header_close#}
10795
10822
{#header_open|Exporting a C Library#}
10796
10823
<p>
10797
10824
One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages
You can’t perform that action at this time.
0 commit comments