1) There's some stray foo(pick_random.interface()); and foo(pick_seq_iface); in the main() example which refer to a function that's not defined.
2) This "stinks" a bit because of the widespread use of *c_void, which is documented to be used only for C ABI compatibility. One way you can avoid this is to define a const AnyInterface = opaque {}; and then replace the various *c_void with *AnyInterface. In theory this could also be just anyopaque in the future.
Oh, my bad! I don't know how I missed the definition of foo().
As for *c_void vs opaque {}, AFAIK they're functionally identical, but opaque {} allows you to define a strong type alias whereas *c_void will accept just about any pointer. In retrospect, it probably doesn't matter very much in this specific case, but it seems good form anyway.
Two things:
1) There's some stray
foo(pick_random.interface());
andfoo(pick_seq_iface);
in themain()
example which refer to a function that's not defined.2) This "stinks" a bit because of the widespread use of
*c_void
, which is documented to be used only for C ABI compatibility. One way you can avoid this is to define aconst AnyInterface = opaque {};
and then replace the various*c_void
with*AnyInterface
. In theory this could also be justanyopaque
in the future.foo() is defined at the very top of the post.
I'm not sure how to feel about using
*c_void
. Does usingopaque
change the code/cast in a good way?Oh, my bad! I don't know how I missed the definition of
foo()
.As for
*c_void
vsopaque {}
, AFAIK they're functionally identical, butopaque {}
allows you to define a strong type alias whereas*c_void
will accept just about any pointer. In retrospect, it probably doesn't matter very much in this specific case, but it seems good form anyway.*c_void
is going to be renamedanyopaque
github.com/ziglang/zig/issues/323
I know, but that just means it'll accept any "opaque" type, as I clarified in zig.news/jmc/comment/51.