[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: keyword_set() NullObject and NullPointer

Luis (euluis@netscape.net) writes:

> IDL version 5.1.1, Windows
> in the online documentation of keyword_set() isn't refered
> what is the behavior with Null object and Null Pointer.
> I've tryed and it returns 0, which is good for me, because
> that is the behavior that fits my needs. Because I'm developing
> an complex program and that behavior isn't documented, I'm
> afraid that it could change. Is that possible? Someone from RDI
>  told you something?

No one from RDI told be nuttin', but I would be very
careful if I were you. Something in the tone of your
question leads me to think there is a VERY strong
possibility that you are using Keyword_Set for the 
wrong reason.

Keyword_Set should ONLY be used with keywords that
have a binary-type functionality. They are on or off,
true or false, yes or no, 0 or 1. Using Keyword_Set
for any other purpose will get you into trouble sooner
or later.

Having said that, Keyword_Set doesn't behave with pointers
exactly the way I would hope it would. The documentation
says that Keyword_Set returns a 0 if the augment is 0
or undefined. If the argument is anything else at all, 
it returns a 1. (Notice it says NOTHING whatsoever about
whether the keyword is *used* or not. Nor can it tell you
this information. And if you thought it did, you would
be mistaken.)

What it does tell you about pointers (and the more I
think about it the more I am sure there is NEVER a
reason to be using Keyword_Set with pointers) is whether
you have a valid pointer or not:

   a = Ptr_New() ; Null and invalid pointer.
   Print, Keyword_Set(a)

   b = Ptr_New(5) ; Valid pointer.
   Print, Keyword_Set(b)
   c = Ptr_New(/Allocate_Heap) ; Valid pointer to undefined variable.
   Print, Keyword_Set(c)

Perhaps that is the information you wanted from Keyword_Set, but
if it is, a much safer way to get it would be to use Ptr_Valid().


David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155