Is it possible to unite the Union in C?

I was asked in an interview "Is it possible to unite the union?"

I know that struct can refer to itself, but I'm really confused about union . I read in one textbook that the union can self-observe, but he did not say anything on this issue.

Can someone confirm if union or cannot be a reference to itself?

+4
source share
1 answer

sure it can, really just like a struct :

 union toto { union toto* a; unsigned b; }; 

once the toto tag identifier is known as the union union toto* type, union toto* is a pointer to an incomplete type.

It is hard to understand that this knowledge will serve you for anything other than an interview.

+4
source

Source: https://habr.com/ru/post/1380998/


All Articles