[Enterprise Extensions only]

CORBA programming: C++ type mapping for argument passing

Argument type mappings are discussed in this topic and summarized in the two tables below. For the rules that must be observed when passing parameters (in , inout, out, or return value) to a CORBA object implementation, see Argument passing considerations for C++ bindings.

For primitive types and enumerations, the type mapping is straightforward. For in parameters and return values the type mapping is the C++ type representation (abbreviated as "T" in the text that follows) of the IDL specified type. For inout and out parameters the type mapping is a reference to the C++ type representation (abbreviated as "T&" in the text that follows).

For object references, the type mapping uses _ptr for in parameters and return values and _ptr& for inout and out parameters. That is, for a declared interface A, an object reference parameter is passed as type A_ptr or A_ptr&. The conversion functions on the _var type permit the client (caller) the option of using _var type rather than the _ptr for object reference parameters. Using the _var type may have an advantage in that it relieves the client (caller) of the responsibility of deallocating a returned object reference (out parm or return value) between successive calls. This is because the assignment operator of a _ptr to a _var automatically releases the embedded reference.

The type mapping of parameters for aggregate types (also referred to as complex types) are complicated by when and how the parameter memory is allocated and deallocated. Mapping in parameters is straightforward because the parameter storage is caller allocated and read only. For an aggregate IDL type t with a C++ type representation of T the in parameter mapping is const T&. The mapping of out and inout parameters is slightly more complex. To preserve the client capability to stack allocate fixed length types, OMG has defined the mappings for fixed-length and variable-length aggregates differently. The inout and out mapping of an aggregate type represented in C++ as T is T& for fixed-length aggregates and as T*& for variable-length aggregates.

Basic argument and result passing

Data Type In Inout Out Return
short short short& short& short
long long long& long& long
unsigned short ushort ushort& ushort& ushort
unsigned long ulong ulong& ulong& ulong
float float float& float& float
double double double& double& double
boolean boolean boolean& boolean& boolean
char char char& char& char
wchar wchar wchar& wchar& wchar
octet Octet Octet& Octet& Octet
enum enum enum& enum& enum
object reference ptr objref_ptr objref_ptr& objref_ptr& objref_ptr
struct, fixed const struct& struct& struct& struct
struct, variable const struct& struct& struct*& struct*
union, fixed const union& union& union& union
union, variable const union& union*& union*& union*
string const char* char*& char*& char*
wstring const char* char*& char*& char*
sequence const sequence& sequence& sequence*& sequence*
array, fixed const array array array array slice*
array, variable const array array array slice*& array slice*
any const any& any& any*& any*


For an aggregate type represented by the C++ type T, the T_var type is also defined. The conversion operations on each T_var type allows the client (caller) to use the T_var type directly for any directionality, instead of using the required form of the T type ( T, T& or T*&) The emitted bindings define the operation signatures in terms of the parameter passing modes shown in the tableT_var argument and result passing, and the T_var types provide the necessary conversion operators to allow them to be passed directly.

T_var argument and result passing

Data Type In Inout Out Return
object reference_var const object_var& objref_var& objref_var& objref_var
struct_var const struct_var& struct_var& struct_var& struct_var
union_var const union_var& union_var& union_var& union_var
string_var const string_var& string_var& string_var& string_var
sequence_var const sequence_var& sequence_var& sequence_var& sequence_var
array_var const array_var& array_var& array_var& array_var


For parameters that are passed or returned as a pointer type (T*) or reference to pointer(T*&) the programmer should not pass or return a null pointer. This cannot be enforced by the bindings.