Re: Structure Pass By Reference? [message #32880] |
Fri, 15 November 2002 16:28  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Nidhi Kalra (nrk5@cornell.edu) writes:
> I have a very deep structure that looks something like this:
>
> struct = $
> {vmap, $
> a: ptr_new(), $
> b: ptr_new()$
> }
>
> struct = $
> {rindex, $
> x: 0, $
> y: 0 $
> }
>
> where vmap.a is an array of structures of type RINDEX. vmap is an
> actual defined object and rindex is just a structure
>
> in a vmap method i need to access individual elements of a. i tried
> (for example):
>
> rindex1 = (*self.a)[2]
> rindex1.x = 2
>
> I would think that since (*self.a)[2] is a structure of type rindex,
> it would be passed by reference and therefore rindex1.x = 2 would mean
> (self.a)[2].x =2, but this is not the case. Can somebody help me out?
I guess I've been working with IDL for too long, because
I don't find this result surprising at all. You are returning
a subscripted array member. I would expect it to be returned
by value. That is consistent with IDL's rules for this kind of
thing.
If you want to put it back after you have changed it,
you just do this:
rindex1 = (*self.a)[2]
rindex1.x = 2
(*self.a)[2] = rindex1
Cheers,
David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
|
|
|