Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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
peter@hpl.hp.com (Peter Webb) wrote: > This is, at best, a feeble attempt to describe pass by reference. The > parameters are not copied, they are referenced (try passing an array so > large that copying would use up all memory -- you can do it, ergo no > copying happened). > > Time for a rewrite, RSI! I tried it and Peter seems to be correct. IDL pass by reference seems to work the way it should and not the way it is documented. While we are on the subject of documentation, my personal favorite is the way in which the /NO_COPY keyword is documented for the WIDGET_* routines. The paragraph given leaves much to the imagination. On the other hand, the documentation for the HANDLE_* routines makes the operation of this keyword very clear. IMHO, the documentation is much better than it used to be, but there is room for improvement. Ken Knighton knighton@gav.gat.com knighton@cts.com General Atomics San Diego CA
Ken Knighton (knighton@gav.gat.com) wrote: : peter@hpl.hp.com (Peter Webb) wrote: : >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. : 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. As Ken mentions, this behavior is documented. However, the whole section on argument passing is very badly written. From the PV-Wave manual, which I believe is a direct copy of the IDL manual, "When a procedure...is called, the actual parameters are copiend ito the formal parameters... On exit,...formal are copied back to actual if they are not expressions or constants." This is, at best, a feeble attempt to describe pass by reference. The parameters are not copied, they are referenced (try passing an array so large that copying would use up all memory -- you can do it, ergo no copying happened). Time for a rewrite, RSI! Peter -------------------------------- Peter Webb, HP Labs Medical Dept E-Mail: peter_webb@hpl.hp.com Phone: (415) 813-3756