Skip to content

Instantly share code, notes, and snippets.

@rjtobin
Created September 29, 2019 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjtobin/6b7779116485ca7efbb5d71b4ba013ed to your computer and use it in GitHub Desktop.
Save rjtobin/6b7779116485ca7efbb5d71b4ba013ed to your computer and use it in GitHub Desktop.
zig c pointer question
const c = @cImport({
@cInclude("cfile.h");
});
pub fn main() void {
var x:?[*]const u8 = null;
x = c.some_func(0);
}
const char* some_func(int a)
{
if(a == 0)
return 0;
return "FOO";
}
@nrdmn
Copy link

nrdmn commented Sep 29, 2019

Works:

pub fn main() void {
    var x: ?[*]const u8 = @intToPtr([*c]u8, 0);
    x = null;
}

Also works:

pub fn main() void {
    var x: ?[*]const u8 = null;
    x = @intToPtr(?[*]u8, 0);
}

Doesn't work:

pub fn main() void {
    var x: ?[*]const u8 = null;
    x = @intToPtr([*c]u8, 0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment