comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » A strange behaviour of parameters passing
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: A strange behaviour of parameters passing [message #15696 is a reply to message #15630] Fri, 04 June 1999 00:00 Go to previous messageGo to previous message
Vapuser is currently offline  Vapuser
Messages: 63
Registered: November 1998
Member
Daniel SAGE <daniel.sage@epfl.ch> writes:



Yeah, the answer is don't pass expressions into routines if you want
the routine to change the value of its parameters.

In the first call you make to 'one' (e.g. one, a[*]) the parameter
is passed by _value_ since it's not a variable but an expression (I
think the completely proper way to say this is that what gets passed
is a reference to a temporary variable that is destroyed when the
routine 'one' exits) The second time you call 'one' the parameter is
passed by reference, since you are passing a named variable and not a
temporary one. In that case, you can change the contents of the
parameter and have that change persist after return.

There's nothing wrong with passing expressions, unless you want to
change the value of the parameter inside a routine. It would be nice
if they gave us some way of checking whether an expression, rather
than a named variable, had been passed in. I am unaware of any such
capability.

I don't think you can call this is a bug; I think it's a feature.

William



> Hi,
> Who can explain me the strange behaviour when I passed my parameters ?
> I create a small and stupid example to see the disfunctionning of IDL.
> Why the first call of the procedure 'one' returns 1 and the second call
> return 2 ? According the documentation of IDL, the second calling is
> correct but
> not the first calling.
> Thank you
>
> pro one, b
> b[0] = 2
> end
>
> pro two
> a = intarr(1)
> a[*] = 1
> one, a[*]
> print, a
> one, a
> print, a
> end
>
> % Compiled module: ONE.
> % Compiled module: TWO.
> IDL> two
> 1
> 2
>
> ------------------------------------------------------------ ----------------
> Daniel Sage
> EPFL - Swiss Federal Institute of Technology - http://www.epfl.ch
> BIG - Biomedical Imaging Group - http://bigwww.epfl.ch
>
> Address: EPFL, DMT/IOA, BM, CH-1015 Lausanne, Switzerland
> Tel: +41 21 693 5189
> Fax: +41 21 693 3701
> Email: daniel.sage@epfl.ch
> ------------------------------------------------------------ ----------------

--
William Daffer: 818-354-0161: vapuser@catspaw.jpl.nasa.gov
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: regular expressions
Next Topic: Re: Making MPEG Movies

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Mon Dec 01 04:11:11 PST 2025

Total time taken to generate the page: 1.59990 seconds