Top "Unions" questions

The plural of a keyword in the C family of languages for declaring a union data type.

Can a union be initialized in the declaration?

For example, say we have a union typedef union { unsigned long U32; float f; }U_U32_F; When a variable …

c initialization declaration unions
gcc, strict-aliasing, and casting through a union

Do you have any horror stories to tell? The GCC Manual recently added a warning regarding -fstrict-aliasing and casting a …

c gcc type-conversion unions strict-aliasing
What are Unrestricted Unions proposed in C++11?

I gather unrestricted unions as one of the functionality being put forth in C++11. Can anyone please explain the semantics …

c++ c++11 unions
Usage of union inside a class

I saw some code as follows: class A { private: union { B *rep; A *next; }; // no variables of this anonymous defined! …

c++ class unions
c union and bitfields

Can bitfields be used in union?

c bit-fields unions
How to check what type is currently used in union?

let's say we have a union: typedef union someunion { int a; double b; } myunion; Is it possible to check what …

c unions
Why do unions have a deleted default constructor if just one of its members doesn't have one?

N3797::9.5/2 [class.union] says: If any non-static data member of a union has a non-trivial default constructor (12.1), copy constructor (12.8), move …

c++ constructor unions
Union element alignment

If I have a union, C standard guarantees that the union itself will be aligned to the size of the …

c alignment unions
Memory layout of union of different sized member?

typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t; Here int and __…

c unions
What is the equivalent of boost::variant in the C++ standard library?

I am looking for an alternative to C-style union. boost::variant is one such option. Is there anything in std …

c++ boost unions variant boost-variant