Hacker News new | ask | show | jobs
by michaelg7x 1174 days ago
What are the downsides of keeping the public fields in a struct which is in turn embedded in a private struct created by the library? Inferring the "outer offset" could get irritating but it depends on your tolerance of additional complexity (in every public function...).
2 comments

> What are the downsides of keeping the public fields in a struct which is in turn embedded in a private struct created by the library?

That seems similar to using "opaque {}", if I am understanding you correctly?

I think either of those solutions could potentially work, at the cost of one explicit cast in each function that actually needs to access the data. I would love to know if this works well enough in practice.

The answer in C would be it constrains ordering/packing of fields, so you'd end up with N public/private wrappers and generally a lot of line noise, but I have a vague recollection that zig reorders fields as it sees fit anyway making that a non-issue