Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
union is a C++ keyword to declare a struct that uses the same memory for all elements.
In the example below, a union is created consisting of a double and an int. When the int is modified, the double is modified as well (and vice versa).
#include <boost/static_assert.hpp> |
Screen output:
int : 1000
double: 4.94066e-321
int : 0
double: 1000
|
Consider never using unions [1]. Use unions to save space [2]. Never use unions for type conversion [2].
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.