4 ms·
> … a technique called "subtyping" is used, where struct B, who's first member is a struct A, is cast as that struct A to properly conform to an interface. It's
by UncleEntity 5y ago
> … a technique called "subtyping" is used, where struct B, who's first member is a struct A, is cast as that struct A to properly conform to an interface. It's supposedly common in C (that's what I was told in #hare, anyway), though this is the first time I'm encountering it.
How much C have you looked at if you’ve never seen that pattern (or ‘story’, not up on the lingo)?
Is there another way to do this I’m not aware of because it’s so common I thought it was just common.
—edit—
Thinking about this for a minute there’s another ‘story’ where you use the least significant bit(s) as a tag and use that to differentiate between object types but that is definitely not too common, this hextree library I found somewhere uses it to tell a leaf from a branch and I’m really tempted to just replace it with the previously mentioned ‘subtyping’.
- jibalt 5y agoThe article isn't well informed ... e.g., it says "In all the languages I know of, you can't break out of a loop from an inner loop" but you can do so in all the languages it mentions at the top: Rust, Zig, and Myrddin, as well as many others.
- UncleEntity 5y agoI was thinking the same thing where Java has had this since 1995 but was too lazy to look it up to make sure. No language I actually use has it but I know about it from playing around with a java 1.1 parser project I’ve been slowly working on.
- wchar_t 5y ago(Author here.) Fair enough, I should have done my research on that. I had barely touched Myrddin, was just beginning to look into Zig, and hadn't heard of (or felt the need for) that feature in Rust at the time I wrote that post.