langref: fix malloc return type

This commit is contained in:
XXIV 2023-11-04 13:17:44 +03:00 committed by Veikka Tuominen
parent 9ced27dace
commit 5ea973dc39

View file

@ -6201,7 +6201,7 @@ struct Foo *do_a_thing(void) {
<p>Zig code</p> <p>Zig code</p>
{#syntax_block|zig|call_malloc_from_zig.zig#} {#syntax_block|zig|call_malloc_from_zig.zig#}
// malloc prototype included for reference // malloc prototype included for reference
extern fn malloc(size: usize) ?*u8; extern fn malloc(size: usize) ?[*]u8;
fn doAThing() ?*Foo { fn doAThing() ?*Foo {
const ptr = malloc(1234) orelse return null; const ptr = malloc(1234) orelse return null;
@ -6210,7 +6210,7 @@ fn doAThing() ?*Foo {
{#end_syntax_block#} {#end_syntax_block#}
<p> <p>
Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr" Here, Zig is at least as convenient, if not more, than C. And, the type of "ptr"
is {#syntax#}*u8{#endsyntax#} <em>not</em> {#syntax#}?*u8{#endsyntax#}. The {#syntax#}orelse{#endsyntax#} keyword is {#syntax#}[*]u8{#endsyntax#} <em>not</em> {#syntax#}?[*]u8{#endsyntax#}. The {#syntax#}orelse{#endsyntax#} keyword
unwrapped the optional type and therefore {#syntax#}ptr{#endsyntax#} is guaranteed to be non-null everywhere unwrapped the optional type and therefore {#syntax#}ptr{#endsyntax#} is guaranteed to be non-null everywhere
it is used in the function. it is used in the function.
</p> </p>