ARG_PRESENT
The ARG_PRESENT function is useful in user-written procedures that need to know if the lifetime of a value they are creating extends beyond the current routine’s lifetime. This can be important for two reasons:
- To avoid expensive computations that the caller is not interested in.
- To prevent heap variable leakage that would result if the routine creates pointers or object references and assigns them to arguments that are not passed back to the caller.
Example
Suppose that you are writing an IDL procedure that has the following procedure definition line:
PRO myproc, RET_PTR = ret_ptr
The intent of the RET_PTR keyword is to pass back a pointer to a new pointer heap variable. The following command could be used to avoid creating (and possibly losing) a pointer if no named variable is provided by the caller:
IF ARG_PRESENT(ret_ptr) THEN BEGIN
The commands that follow would only be executed if ret_ptr
is supplied and will be copied into a variable in the scope of the calling routine.
Syntax
Result = ARG_PRESENT(Variable)
Return Value
Returns a nonzero value if the following conditions are met:
- The argument to ARG_PRESENT was passed as a plain argument or keyword to the current routine by its caller, and
- The argument to ARG_PRESENT is a named variable into which a value will be copied when the current routine exits.
In other words, ARG_PRESENT returns TRUE if the value of the specified variable will be passed back to the caller.
Arguments
Variable
The variable to be tested.
Version History
5.0 |
Introduced |