Skip to content

Instantly share code, notes, and snippets.

@moysesb
Last active July 31, 2018 20:13
Show Gist options
  • Save moysesb/9d3c82c0f1812045d344d3f70d33a9e2 to your computer and use it in GitHub Desktop.
Save moysesb/9d3c82c0f1812045d344d3f70d33a9e2 to your computer and use it in GitHub Desktop.
zig compiler bug
typedef const struct InvocationTable_ *VM;
struct VM_ {
const struct InvocationTable_ *functions;
};
struct InvocationTable_ {
int (*GetVM)(VM *vm);
};
int agent_callback(VM *vm, char *options);
// ~> zig translate-c --verbose-cimport vm.h
pub const VM = ?[*]const struct_InvocationTable_;
pub const struct_InvocationTable_ = extern struct {
GetVM: ?extern fn(?[*]VM) c_int,
};
pub const struct_VM_ = extern struct {
functions: ?[*]const struct_InvocationTable_,
};
//excised output from stdlib.h etc
pub const InvocationTable_ = struct_InvocationTable_;
pub const VM_ = struct_VM_;
const vm = @cImport({ @cInclude("vm.h"); });
export fn agent_callback(_vm: [*]vm.VM, options: [*]u8) i32 {
return 0;
}
zig -isystem . build-lib vm.zig
vm.zig:1:12: error: compiler bug: @cImport generated invalid zig code
const vm = @cImport({ @cInclude("vm.h"); });
^
?.c:1:1: note: 'VM' depends on itself
TODO: remember C source location to display here
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment