comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Return UNDEFINED from a function
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Return UNDEFINED from a function [message #50730] Wed, 11 October 2006 15:57
MarioIncandenza is currently offline  MarioIncandenza
Messages: 231
Registered: February 2005
Senior Member
Unfortunately, this appears to be possible. This is somewhere between
a) another example of what a dunderhead I am, and b) a serious flaw in
the IDL compiler, and I'm not sure where right now.

Witness this function:

function return_undefined,this=this,that=that
on_error,2
if n_elements(this) ne 0 then thisthat=0
if n_elements(that) ne 0 then thisthat=1
return,thisthat
end

Now, in IDL:
% Compiled module: RETURN_UNDEFINED.
IDL> test=return_undefined()
% Variable is undefined: <UNDEFINED>.
% Execution halted at: $MAIN$
IDL> help,return_undefined()
<Expression> UNDEFINED = <Undefined>

This is the actual root cause of the "Variable is undefined:
<UNDEFINED>" error I experienced a few months back.

What's going on here is that IDL never checks to see if the value in
the RETURN statement is defined. So, if you use HELP, you can
immediately tell that your function is for some reason trying to return
an undefined variable. But if you use PRINT, or simply try to assign
the results, you get this profoundly unhelpful error.

Shouldn't the RETURN statement check to see that its argument is
defined? Am I wrong that this is bad compiler behavior?

--Edward H.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Land/Water Database
Next Topic: How to Sort/Uniq a list and keep its original index

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 00:52:27 PDT 2025

Total time taken to generate the page: 0.64056 seconds