Skip to content

Commit 9996dc3

Browse files
committed
langref: document extern variadic functions
Add a new subsection within the C section, documenting extern variadic functions.
1 parent 959c10c commit 9996dc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

doc/langref.html.in

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10792,6 +10792,33 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
1079210792
<p>{#syntax#}ptr_to_struct_array[index].struct_member{#endsyntax#}</p>
1079310793
{#header_close#}
1079410794

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#}
1079510822
{#header_open|Exporting a C Library#}
1079610823
<p>
1079710824
One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages

0 commit comments

Comments
 (0)