unsigned
char
and unsigned short
promote to
unsigned int
.)
##
operators when a valid token results after
concatenation, except that adjoining white space is not deleted.
If the resulting token is not valid, the comment in a macro
replacement is deleted.
Variant structure and union declarations allow reference to members of nested aggregates without having to refer to intermediate structure or union identifiers. When a variant structure or union declaration is nested within another structure or union declaration, the enclosed variant aggregate ceases to exist as a separate aggregate, and DEC C copies its members to the enclosing aggregate.
Variant structures and unions are declared using the
variant_struct
and variant_union
keywords. The format of these declarations is the same as that
for regular structures or unions, with the following exceptions:
Initialization of a variant structure or union is the same as that of a normal structure or union.
With the VAX C compatibility option, two structures or unions in an assignment operation need only have the same size, rather than requiring the same members and member types.
The following example shows the format of a variable structure declaration, and how to reference members of a variant structure:
#include <stdio.h> enum packet_type {TEXT, INTEGER}; /* This structure can contain either a text_packet or an integer value. It can only contain one of these at a time, since they share the same storage. */ struct packet { enum packet_type type; variant_union { variant_struct { int str_size; char *text; } text_packet; variant_struct { int value; } value_packet; } text_or_int; } packet = {TEXT, 24 ,"I love the color purple"}; main() { if (packet.type == TEXT) printf(" %s. \n",packet.text); else printf(" %d \n", packet.value); packet.type = INTEGER; packet.value = 42; printf(" The meaning of life, the universe, and everything is: %d. \n", packet.value); }