Every entity in IDL has an associated data type and structure. The structure of an expression determines whether the expression can represent a single value or multiple values. IDL expressions can be either scalars (with exactly one value) or arrays (with one or more values). The data type and structure of an expression depend on the data type and structure of its operands.

Tip: You can determine the data type of an expression by returning the type code of the expression.

Hierarchy of IDL Data Types


Unlike many other languages, the data type and structure of most expressions in IDL cannot be determined until the expression is evaluated. Because of this, care must be taken when writing programs. For example, a variable can be a scalar byte variable at one point in a program while at a later point the same variable can hold a complex array. The twelve atomic data types in decreasing order of precedence are as follows:

  • Double-precision complex floating-point (DCOMPLEX)
  • Complex floating-point (COMPLEX)
  • Double-precision floating-point (DOUBLE)
  • Floating-point (FLOAT)
  • Signed and unsigned 64-bit integers (LONG64 and ULONG64)
  • Signed and unsigned 32-bit integer (LONG and ULONG)
  • Signed and unsigned 16-bit integer (INT and UINT)
  • Byte/Boolean
  • String

Expression Type


IDL attempts to evaluate expressions containing operands of different data types in the most accurate manner possible. The result of an operation becomes the same data type as the operand with the greatest precedence or potential precision. For example, when adding a byte variable to a floating-point variable, the byte variable is first converted to floating-point, then added to the floating-point variable, yielding a floating-point result. When adding a double-precision variable to a complex variable, the result is double-precision complex, because the double-precision complex type has a higher position in the hierarchy of data types. See Hierarchy of IDL Data Types for the order of precedence.

Note: Signed and unsigned integers of a given width have the same precedence. In an expression involving a combination of such types, the result is given the type of the leftmost operand.

Note: Boolean variables are treated just like byte variables. The result of any math expression using boolean variables will be a byte variable.

When writing expressions with mixed data types, care must be taken to obtain the desired results. For example, assume the variable A is an integer variable with a value of 5. The following expressions yield the indicated results:

Operation

Result

Notes

A/2

2 (int)

Integer division is performed. The remainder is discarded.

A/2.0

2.5 (float)

The value of A is first converted to floating.

A/2 + 1.0

3.0 (float)

Integer division is done first because of operator precedence.

A/2.0 + 1

3.5 (float)

Division is done in floating, then the 1 is converted to float and added.

A + 5u

10 (int)

Signed and unsigned integer operands have the same precedence, so the left-most operand determines the result type.

5u + A

10 (uint)

The left-most operand determines the result type between types with the same precedence.

A < 65535u

–1 (int)

Again, left operand determines the type. 65535 converted to int gives –1, which is smaller than A.

65535u < A

5 (uint)

Again, left operand determines the type. A=5 is converted to uint, which is smaller than A.

Note: When other data types are converted to complex type, the real part is set equal to the original value and the imaginary part is set to zero.

Note: When a string type appears as an operand with a numeric data type, the string is converted to the type of the numeric term. For example: '123' + 123.0 is 246.0, while '123.333' + 33 gives the result 156 because 123.333 is first converted to integer type. In the same manner, 'ABC' + 123 also causes a conversion error.

Expression Structure


IDL expressions >can contain operands that are either scalars or arrays, just as they can contain operands with different types. Conversion of variables between the scalar and array forms is independent of data type conversion. An expression will yield an array result if any of its operands is an array, as shown in the following table:

Operands

Result

Scalar : Scalar

Scalar

Array : Array

Array

Scalar : Array

Array

Array : Scalar

Array