Pointer Problem [message #9577] |
Mon, 14 July 1997 00:00 |
J.D. Smith
Messages: 214 Registered: August 1996
|
Senior Member |
|
|
This is a possible pointer problem which may affect some of you. See
what you think about the following code:
IDL> a=ptr_new()
IDL> print,ptr_valid(a)
0
IDL> help,*a
% Unable to dereference NULL pointer: A.
% Execution halted at: $MAIN$
IDL> b=ptr_new(notavalidvariable)
IDL> help,b
B POINTER = <PtrHeapVar2>
IDL> print,ptr_valid(b)
1
IDL> help,*b
<PtrHeapVar2> UNDEFINED = <Undefined>
IDL> print,*b
% PRINT: Variable is undefined: <PtrHeapVar2>.
% Execution halted at: $MAIN$
Note here that 'notavalidvariable' is a fake, undefined variable. B is
assigned to an undefined heap variable, as if /ALLOCATE_HEAP had been
specified. Consequently, ptr_valid see's b as valid. This behavior is
mildly irksome in that the convenience of assigning pointers without
checking the contents of that which they are being assigned to is lost.
It is also non-intuitive.
JD
|
|
|