@OpaqueType
@OpaqueType
@OpaqueType() type
Creates a new type with an unknown (but non-zero) size and alignment.
This is typically used for type safety when interacting with C code that does not expose struct details. Example:
test.zig
const Derp = @OpaqueType();
const Wat = @OpaqueType();
extern fn bar(d: *Derp) void;
export fn foo(w: *Wat) void {
bar(w);
}
test "call foo" {
foo(undefined);
}
``` ```
$ zig test test.zig
/home/andy/dev/zig/docgen_tmp/test.zig:6:9: error: expected type '*Derp', found '*Wat'
bar(w);
^
/home/andy/dev/zig/docgen_tmp/test.zig:6:9: note: pointer type child 'Wat' cannot cast into pointer type child 'Derp'
bar(w);
^
