IDL variables are represented by IDL_VARIABLE structures. The definition of IDL_VARIABLE is as follows:
typedef struct {
UCHAR type
UCHAR flags
IDL_ALLTYPES value
} IDL_VARIABLE
An IDL_VPTR is a pointer to an IDL_VARIABLE structure:
typedef IDL_VARIABLE *IDL_VPTR
The IDL_ALLTYPES union is defined as:
typedef union {
UCHAR c
IDL_INT i
IDL_UINT ui
IDL_LONG l
IDL_ULONG ul
IDL_LONG64 l64
IDL_ULONG64 ul64
float f
double d
IDL_COMPLEX cmp
IDL_DCOMPLEX dcmp
IDL_STRING str
IDL_ARRAY *arr
IDL_SREF s
IDL_HVID hvid
}IDL_ALLTYPES
The basic scalar types are contained directly in this union, while arrays and structures are represented by the IDL_ARRAY and IDL_SREF structures that are discussed later in this chapter. The type field of the IDL_VARIABLE structure contains one of the type codes discussed in Types. When a variable is initially created, it is given the type code IDL_TYP_UNDEF, indicating that the variable contains no value.
The flags field is a bit mask that specifies information about the variable. As a programmer adding code to the IDL system, you will rarely need to set bits in this mask. These bits are set by whatever portion of IDL created the variable. You can check them to make sure the characteristics of the variable fit the requirements of your routine (see Checking Arguments).
The defined bits in the mask are:
IDL_V_CONST
If this flag is set, the variable is actually a constant. This means that storage for the IDL_VARIABLE resides inside the code section of the user procedure or function that used it. The IDL compiler generates such IDL_VARIABLEs when an expression involving a constant occurs. For example, the IDL statement:
PRINT, 23 * A
causes the compiler to generate a constant for the “23”. You must not change the value of this type of “variable.”
IDL_V_TEMP
If this flag is set, the variable is a temporary variable. IDL maintains a pool of nameless IDL_VARIABLEs that can be checked out and returned as needed. Such variables are used by the interpreter to temporarily store the results of expressions on the stack. For example, the statement:
PRINT, 2 * 3
will cause the interpreter to go through a sequence of events similar to:
- Push a constant variable for the 2 on the stack.
- Push a constant variable for the 3 on the stack.
- Allocate a temporary variable, pop the two constants from the stack, perform the multiplication with the result going into the temporary variable.
- Push the temporary variable onto the stack.
- Call the PRINT system procedure specifying one argument.
- Remove the argument to PRINT from the stack, and return the temporary variable.
Temporary variables are also used inside user procedures and functions. See Temporary Variables .
IDL_V_ARR
If this flag is set, the variable is an array, and the value field of the IDL_VARIABLE points to an array descriptor.
IDL_V_FILE
If this flag is set, the variable is a file variable, as created by IDL’s ASSOC function.
IDL_V_DYNAMIC
If this flag is set, the memory used by this IDL_VARIABLE is dynamically allocated. This bit is set for arrays, structures, and for variables of IDL_TYP_STRING (because the memory referenced via the string pointer is dynamic).
IDL_V_STRUCT
If this flag is set, the variable is a structure, and the value field of the IDL_VARIABLE points to the structure descriptor. For implementation reasons, all structure variables are also arrays, so IDL_V_STRUCT also implies IDL_V_ARR. Therefore, it is impossible to have a scalar structure. However, single-element structure arrays are quite common.
Because structure variables have their type field set to IDL_TYP_STRUCT, the IDL_V_STRUCT bit is redundant. It exists for efficiency reasons.