#zig array to c void pointer
1 messages · Page 1 of 1 (latest)
I guess more specifically, how do I actually use @as because the documentation doesn't make much sense
take the address of the array
&array?
or if you want it explicit use @ptrCast(&array)

don't do that if not necessary
It's better when reading the code
it isn't really, and it introduces a bug if the signature of function ever changes to something more strict and implicitly continues to allow you passing the array pointer without warning you, since you used @ptrCast
you should not use casts if you do not need to
It's used in stdlib and I thought it was there for reading purpose
it is used in the stdlib where it is necessary, which, for the majority of casts between pointers, it is
but we're talking about a coercion here, where it simply isn't
would you mind pointing these examples you're referring to out?
note: there is a specific case where *T isn't allowed to coerce to *anyopaque, and it's when T = *U
that is to say, **U can't coerce to *anyopaque
if you see any @ptrCasts used for any coercion other than that, then a PR to remove those would be beneficial
why is that?
when dealing with multiple levels of pointer indirection it is a common footgun in a language like C to accidentally "cast at the wrong depth"
ok makes sense i guess
limiting coercion to *anyopaque to only one level of depth avoids this footgun
meaning 90% of cases can work easily with it, where 10% of cases have to do a little more work to express proper intent
this is an example of where the operand may be a pointer type
if Context = *U, then .context = &self.context would be a compile error

oh shit when did they change the reader interface
is performance impacted in any way when everything refers to the type erased AnyReader under the hood?
as per the measurements done during the PR, turns out no
though some benchmarks demonstrated that AnyWriter did worsen performance
so somethin odd happened there
hmm wouldn't it be great to have a single interface Reader that could be used with compile time generics or dynamically at runtime...
that is kind of what this is
but its two seperate things with a ton of boilerplate because we have to diy interfaces whenever we need them
yeah, "when we need them" being the key phrase
imagine a world where trait Reader {...}
seems like it would mostly run counter to what the change is trying to solve (that is, reducing code bloat)
it would be a general interface mechanism that allows you to decide between compile time or runtime generics at the use site, like the beloved rustlang
you could already do that now with this mechanism just by continuing to accept anytype
anyway, to #bikeshed with you
yes but the definition of AnyReader + GenericReader is much more complicated with a lot of manual work that could be done automatically in a consistent fashion by zig