authorgravatar for manlio.perillo@gmail.comManlio Perillo <manlio.perillo@gmail.com> 2022-12-12 11:32:48+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-13 15:09:08-05:00
log35c6fe665c7f3f8ba14aaee97c832000cbf5ddc2
tree673e7a2588b379734b4ed9c231cd4f58c23dde8c
parent332020f3103366d54c518be2e8a57cf440a254de

langref: document extern variadic functions

Add a new subsection within the C section, documenting extern variadic functions.

1 files changed, 27 insertions(+), 0 deletions(-)

doc/langref.html.in+27
...@@ -10802,6 +10802,33 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke...@@ -10802,6 +10802,33 @@ pub const MAKELOCAL = @compileError("unable to translate C expr: unexpected toke
10802 <p>{#syntax#}ptr_to_struct_array[index].struct_member{#endsyntax#}</p>10802 <p>{#syntax#}ptr_to_struct_array[index].struct_member{#endsyntax#}</p>
10803 {#header_close#}10803 {#header_close#}
1080410804
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#}
10810const std = @import("std");
10811const testing = std.testing;
10812
10813pub extern "c" fn printf(format: [*:0]const u8, ...) c_int;
10814
10815test "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#}
10825export fn printf(format: [*:0]const u8, ...) c_int {
10826 _ = format;
10827
10828 return 0;
10829}
10830 {#code_end#}
10831 {#header_close#}
10805 {#header_open|Exporting a C Library#}10832 {#header_open|Exporting a C Library#}
10806 <p>10833 <p>
10807 One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages10834 One of the primary use cases for Zig is exporting a library with the C ABI for other programming languages