|
CC78K4 Datasheet, PDF (63/523 Pages) NEC – CC78K4 Ver.2.30 or Later, C Compiler Language | |||
|
◁ |
CHAPTER 3 DECLARATION OF TYPES AND STORAGE CLASSES
The next example is the same as the above example of array initialization.
Char s[ ] = {âaâ, âbâ, âcâ, â\0â},
t[ ] = { âaâ, âbâ, âcâ};
The next example defines p as âpointer to charâ type and the member is initialized by a character string literal so
that the length indicates 4 âchar arrayâ type objects.
char *p = âabcâ ;
(4) Initialization of aggregate or union type objects
⢠Aggregate type
An aggregate type object is initialized by a list of initializers described in ascending order of subscripts or
members. The initializer list to be specified must be enclosed in braces.
If the number of initializers in the list is less than the number of aggregate members, the members not
covered by the initializers will be implicitly initialized just the same as an object that has static storage
duration.
With an array of an unknown size, the number of its elements is governed by the number of initializers and the
array will no longer become an incomplete type.
⢠Union type
A union type object is initialized by an initializer for the first member of the union that is enclosed in braces.
In the following example, the array âxâ with an unknown size will change to a one-dimensional array that has
three elements as a result of its initialization.
int x[ ] = {1, 3, 5} ;
The next example shows a complete definition which has initializers enclosed in braces. â{1, 3, 5}â initializes
ây [0] [0]â, ây [0] [1]â, and ây [0] [2]â in the 1st line of the array object ây[0]â. Likewise, in the second line, the
elements of the array objects ây [1]â and ây [2]â are initialized. The initial value of ây[3]â is 0 since it is not
specified.
char y [4] [3] = {
{1, 3, 5},
{2, 4, 6},
{3, 5, 7},
};
The next example produces the same result as the above example.
char z[4][3] = {
1, 3, 5, 2, 4, 6, 3, 5, 7
};
Userâs Manual U15556EJ1V0UM
63
|
▷ |