Hacker News new | ask | show | jobs
by alcover 357 days ago
> Beware that only tagged unions are considered the same type

I don't get it. Tagged union is just a design pattern.

1 comments

By 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.
Exactly, 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;
Yep, 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)