RAD Studio
ContentsIndex
PreviousUpNext
Unions

This section contains Union topics.

Name 
Description 
Union types are derived types sharing many of the syntactic and functional features of structure types. The key difference is that a union allows only one of its members to be "active" at any one time. The size of a union is the size of its largest member. The value of only one of its members can be stored at any time. In the following simple case,  
A union that does not have a tag and is not used to declare a named object (or other type) is called an anonymous union. It has the following form:  
The general declaration syntax for unions is similar to that for structures. The differences are:
  • Unions can contain bit fields, but only one can be active. They all start at the beginning of the union. (Note that, because bit fields are machine dependent, they can pose problems when writing portable code.)
  • Unlike C++ structures, C++ union types cannot use the class access specifiers: public, private, and protected. All fields of a union are public.
  • Unions can be initialized only through their first declared member:
 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!