4 ms·
> Beware that only tagged unions are considered the same type I don't get it. Tagged union is just a design pattern.
by alcover 1y ago
> Beware that only tagged unions are considered the same type
I don't get it. Tagged union is just a design pattern.
- wahern 1y agoBy tagged they mean have an identifier. Compare > struct { ... } foo; and > struct bar { ... } foo; The latter has an identifier, bar; the former doesn't. The standard uses tag to refer to the identifier name, if any, in an enum, struct, or union declaration.
- teo_zero 1y agoExactly, thank you. I've always called "tag" the id that optionally follows struct/union/enum. Is it the wrong word? Some specs call it "name", but "unnamed union" sounds dangerously similar to "anonymous union", which is a different concept, namely (no pun!) an unnamed member of an outer struct or union whose submembers can be accessed as if they belong in the outer one. E.g. struct { struct { int m; }; // no name: anonymous struct s; s.m = 1;
- wahern 1y agoYep, tag is the correct terminology. See, e.g., section 6.7.3.4 Tags in N3220 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)