mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
langref: fix malloc return type
This commit is contained in:
parent
9ced27dace
commit
5ea973dc39
1 changed files with 2 additions and 2 deletions
|
|
@ -6201,7 +6201,7 @@ struct Foo *do_a_thing(void) {
|
|||
<p>Zig code</p>
|
||||
{#syntax_block|zig|call_malloc_from_zig.zig#}
|
||||
// malloc prototype included for reference
|
||||
extern fn malloc(size: usize) ?*u8;
|
||||
extern fn malloc(size: usize) ?[*]u8;
|
||||
|
||||
fn doAThing() ?*Foo {
|
||||
const ptr = malloc(1234) orelse return null;
|
||||
|
|
@ -6210,7 +6210,7 @@ fn doAThing() ?*Foo {
|
|||
{#end_syntax_block#}
|
||||
<p>
|
||||
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
|
||||
it is used in the function.
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue