Unions within unions

后端 未结 5 1989
傲寒
傲寒 2020-12-20 20:55

In C, is it possible to define a union within another union? If no, why is it not possible? Or if yes, where can it be used?

5条回答
  •  借酒劲吻你
    2020-12-20 21:04

    Yes, a union may contain another union:

    union foo {
      int x;
      double y;
      union bar {
        char blah[10];
        char *blurga;
      } bletch;
    };
    

    I can't think of a situation where it would be useful (or even desirable), though.

提交回复
热议问题