HP C/iX Reference Manual (31506-90011)

50 Chapter3
Data Types and Declarations
Initialization
As a special case, you can initialize an array of characters with a character string literal. If
the dimension of the array of characters is not provided, the compiler counts the number of
characters in the string literal to determine the size of the array. Note that the terminating
'\0' is also counted. For example:
char message[ ] = "hello";
This example defines an array of characters named message that contains six characters.
It is identical to the following:
char message[ ] = {'h','e','l','l','o','\0'};
You can also initialize a pointer to characters with a string literal:
char *cp = "hello";
This declares the object cp as a character pointer initialized to point to the first character
of the string 'hello'.
It is illegal to specify more initializers in a list than are required to initialize the specified
aggregate. The one exception to this rule is the initialization of an array of characters with
a string literal.
char t[3] = "cat";
This initializes the array t to contain the characters c, a, and t. The trailing '\0'
character is ignored.
If there are not enough initializers, the remainder of the aggregate is initialized to zero.
More examples include:
char *errors[]={
"undefined file",
"input error",
"invalid user"
};
In this example, the array errors is an array of pointers to character (strings). The array
is initialized with the starting addresses of three strings, which will be interpreted as error
messages.
An array with element type compatible with wchar_t (unsigned int) may be initialized by
a wide string literal, optionally enclosed in braces. Successive characters of the wide string
literal initialize the members of the array. This includes the terminating zero-valued
character, if there is room or if the array is of unknown size.
Example
struct SS { int y; };
extern struct SS g(void);
func()
{
struct SS z = g();
}
When initializing a union, since only one union member can be active at one time, the first
member of the union is taken to be the initialized member.