DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with Remote Procedure Calls (RPC)

Unions

RPC/XDR unions are discriminated unions, and look different from C unions. They are more analogous to Pascal variant records than they are to C unions.

   union-definition:
   	union union-ident switch ( simple declaration ) {
   		case-list
   	}
   

case-list: case value : declaration ; case value : declaration ; case-list default : declaration ;

This is an example of a type that might be returned as the result of a ``read data'' operation: if there is no error, return a block of data; otherwise, do not return anything.
   union read_result switch (int errno) {
   case 0:
   	opaque data[1024];
   default:
   	void;
   };
This gets compiled into the following:
   struct read_result {
   	int errno;
   	union {
   		char data[1024];
   	} read_result_u;
   };
   typedef struct read_result read_result;
Notice that the union component of the output struct has the name as the type name, except for the trailing _u.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004