The COMPILE_OPT statement allows you to give the IDL compiler information that changes some of the default rules for compiling the function or procedure within which the COMPILE_OPT statement appears.
RSI recommends the use of
COMPILE_OPT IDL2
in all new code intended for use in a reusable library. We further recommend the use of
COMPILE_OPT idl2, HIDDEN
in all such routines that are not intended to be called directly by regular users (e.g. helper routines that are part of a larger package).
| Note |
COMPILE_OPT opt1 [, opt2, ..., optn]
This argument can be any of the following:
COMPILE_OPT DEFINT32, STRICTARR
A side-effect of making a routine hidden is that IDL will not print a "Compile module" message for it when it is compiled from the library to satisfy a call to it. This makes hidden routines appear built-in to the user.
Background
A predicate expression is an expression that is evaluated as being "true" or "false" as part of a statement that controls program execution. IDL evaluates such expressions in the following contexts:
IF...THEN...ELSE statements? : inline conditional expressionsWHILE...DO statementsREPEAT...UNTIL statementsBy default, IDL uses the following rules to determine whether an expression is true or false:
The LOGICAL_PREDICATE option alters the way IDL evaluates predicate expressions. When LOGICAL_PREDICATE is set for a routine, IDL uses the following rules to determine whether an expression is true or false:
Note on the NOT Operator
When using the LOGICAL_PREDICATE compile option, you must be aware of the fact that applying the IDL NOT operator to integer data computes a bitwise negation (1's complement), and is generally not applicable for use in logical computations. Consider the common construction:
WHILE (NOT EOF(lun)) DO BEGIN ... ENDWHILE
The EOF function returns 0 while the file specified by LUN has data left, and returns 1 when hits the end of file. However, the expression "NOT 1" has the numeric value -2. When the LOGICAL_PREDICATE option is not in use, the WHILE statement sees -2 as false; if the LOGICAL_PREDICATE is in use, -2 is a true value and the above loop will not terminate as desired.
The proper way to write the above loop uses the ~ logical negation operator:
WHILE (~ EOF(lun)) DO BEGIN ... ENDWHILE
It is worth noting that this version will work properly whether or not the LOGICAL_PREDICATE compile option is in use. Logical negation operations should always use the ~ operator in preference to the NOT operator, reserving NOT exclusively for bitwise computations.
Use of STRICTARR can eliminate many uses of the FORWARD_FUNCTION definition.
| Note |
COMPILE_OPT STRICTARR
mystruct = {a:0, b:1}
byindex_0 = mystruct.(0)
Introduced: 5.3.
STRICTARRSUBS option added: 5.6
LOGICAL_PREDICATE option added: 6.0