OOB array indexing with an array gives no error message [message #15702] |
Fri, 04 June 1999 00:00 |
Bobstrosity
Messages: 3 Registered: May 1999
|
Junior Member |
|
|
Array indexing is always a popular thread!
I ran into a seemingly strange feature in IDL
{ x86 Win32 Windows 5.1.1 Jul 20 1998}
If this has been discussed before, and is a well
known feature, my apologies.
It seems that you can index an array with a "bad value"
if that bad value is an array rather than a scaler.
The Point: some code could potentially run off the end of
an array by replicating the last part, without telling you.
(Below I show the result of some IDL commands)
;Make an array:
test = findgen(10)
IDL> help,test
TEST FLOAT = Array[10]
;Then acces it an index value that is out of bounds.
IDL> print,test(100)
% Attempt to subscript TEST with <INT ( 100)> is out of range.
; now change the 100 <Expression> INT = 100, to [100]
<Expression> INT = Array[1]
IDL> print,test([100])
9.00000
IDL> help,test([100])
<Expression> FLOAT = Array[1]
IDL> print,test[test+100]
9.00000 9.00000 9.00000 9.00000 9.00000
9.00000 9.00000 9.00000 9.00000 9.00000
IDL> help,test[test+100]
<Expression> FLOAT = Array[10]
Also,
IDL> print,test(-1)
% Attempt to subscript TEST with <INT ( -1)> is out of range.
IDL> print,test([-1])
0.000000
Also,
IDL> test = indgen(10,10,10,10)
IDL> help,test
TEST INT = Array[10, 10, 10, 10]
IDL> print,test(-1,-1,-1,55)
% Attempt to subscript TEST with <INT ( -1)> is out of range.
IDL> print,test([-1],[-1],[-1],[55])
9000
; which is
IDL> print,test(0,0,0,9)
9000
anyways, I just thought it was neat,
a great way to sneak errors into your code!
have a NICE life!
bob
|
|
|