English
Language : 

CC78K4 Datasheet, PDF (130/523 Pages) NEC – CC78K4 Ver.2.30 or Later, C Compiler Language
CHAPTER 7 STRUCTURES AND UNIONS
7.2 Unions
As mentioned earlier, a union is a collection of members that share the same memory space (or overlap in
memory).
(1) Declaration of union and union variable
A union declaration list and a union variable are declared with the keyword union. Any “tag” name can be given
to the union declaration list. Subsequently, the union variables of the same union may be declared using this tag
name.
[Declaration of union]
union tag name {union declaration list} variable name;
In the following example, in the first union declaration, char type arrays “name”, “addr”, and “tel” that have the
tag name “data” are specified and “no1” is declared as the union variable. In the second union declaration, the
union variables “no2, no3, no4, and no5”, which are of the same union as “no1”, are declared.
union data {
char name [12];
char addr [50];
char tel [12];
} no1;
union data no2, no3, no4, no5;
(2) Union declaration list
A union declaration list specifies the structure of a union type to be declared. Individual elements in the union
declaration list are called members and an area is allocated for each of these members in the order of their
declaration. In the following [Example of union declaration list], an area is allocated to ‘c’, which becomes the
largest area of the members. The other members are not allocated new areas but use the same area.
Neither an incomplete type (an array of unknown size) nor a function type can be specified as the type of each
member same as the union declaration list.
Each member can have any object type other than the above two types.
[Union declaration list]
int a;
char b [7];
char c [5] [10];
130
User’s Manual U15556EJ1V0UM