OSF DCE Application Development Guide--Introduction and Style Guide

OSF DCE Application Development Guide—Introduction and Style Guide
6.3 RPC Data Types
IDL provides both a number of primitive data types—such as various sizes of integers
and floats, bytes, and booleans—as well as pointers and a variety of constructed types
based on the primitive types. The use of the primitive types is quite straightforward. The
only important policy issues have to do with IDL data type to C data type mappings and
with character handling. Pointers and the constructed types raise many more policy and
style issues, and the bulk of this chapter is devoted to describing them.
6.3.1 IDL to C Type Mappings
Many of the primitive C data types represent items of different sizes on different
machines. For example, an int may be 16 bits on one machine and 32 bits on another.
These ambiguities can cause portability problems for some C programs, and they are
intolerable for RPC programs. A parameter to an RPC call must represent the same size
data item on both the client and server machine, whatever the machine architectures.
This means that when IDL declarations are compiled to generate C language headers and
stubs, a given IDL type must always be declared in the corresponding C code as a C type
of a specific length, no matter what machine the IDL compilation is done on.
To achieve this, the following must be true:
1. Each IDL primitive type is always represented in the generated C files, by a
specific defined C type
2. Each of the specific defined C types is defined by the local implementation of DCE
so that it represents a data type of the correct length.
For example, a parameter declared in the IDL as a short, will be declared in the IDL
generated header file as the defined type idl_short_int. Each implementation of DCE
then defines the idl_shor_int type correctly for the local C compiler and machine
architecture to be an integer 16 bits long. For example, on a 32-bit machine, the
idl_short_int type is typically defined as a short int.
When you write application code that refers to a parameter declared in the IDL, you must
use a type that declares a data item of the same length. The safest policy is to use the
same specific defined C type used in the headers and stubs. For example, your IDL file
might declare the following:
void my_op([in,out] short var);
In this case, your server manager code would contain an function that looks something
like this:
void my_op(idl_short_int var)
{
.
.
6 6 Tandem Computers Incorporated 124246