Re: [Q] readf into an array error [message #5723 is a reply to message #5714] |
Sat, 03 February 1996 00:00  |
Ken Knighton
Messages: 44 Registered: May 1995
|
Member |
|
|
peter@hpl.hp.com (Peter Webb) wrote:
> Iarla Kilbane-Dawe (iarla@atm.ch.cam.ac.uk) wrote:
>
> : Hello,
>
> : why does IDL give me an error when I try to do?
>
> : a=fltarr(10)
> : i = 0
> : readf,unit,a(i)
>
> This is due to the argument passing mechanism used in IDL. If an array
> is passed to a function, it is passed by reference. If a subarray is
> passed, it is passed by value, and thus cannot be overwritten.
Thanks for the much better description than I gave earlier. One can
also create this problem by using a structure member (a.b) as the
argument. It has been awhile since I thought about it much, so I was a
little bit hazy with my answer.
This little gotcha can really ruin your day if you write or use a
routine that passes data back to the calling routine through arguments
and then use a subarray or a structure member for the argument.
Thinking about this piece of trivia again will probably inoculate me
against this bug for another year.
By the way, I found the documentation for this on page 10-7 of the
user's guide. This documents everything except that structure
members are passed by value. This tidbit is documented on page
7-5 of the user's guide.
Ken Knighton knighton@gav.gat.com knighton@cts.com
General Atomics
San Diego CA
|
|
|