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

Home » Public Forums » archive » structure arguments sometimes behave like value types - why?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
structure arguments sometimes behave like value types - why? [message #53606] Fri, 20 April 2007 13:10
justspam03 is currently offline  justspam03
Messages: 36
Registered: October 2003
Member
Hi all,

according to the IDL reference, structures (as a whole) are treated
like reference types when supplied as an argument. A small test
program of the kind

pro main
ns = { nullableString, hasValue: 0, value: '' }
a = { nullableString }
a.value = '3'
changeval, a
print, a.value
end
pro changeval, s
s.value = '4'
end

confirms this - after the call to changeval, a.value has value '4'.
However, when the structure is an object variable as in the example
appended below, it seems that only a copy of structtest.val is
exchanged, not a reference to it. The final call to printValue in
'main' prints a '1'.
Could someone please explain why? What am I missing?
Thanks a lot
Oliver



pro main

ns = { nullableString, hasValue: 0, value: '' }

x = obj_new('structtest') ; object contains membervariable of type
nullableString
x->set, '1' ; set value of nullableString to '1'
x->printValue ; and print
b = x->getStruct() ; get reference? value?
b.value = '2'
x->printValue ; result is still '1' ! Why?
end

function structtest::init
return, 1
end

pro structtest::set, value
self.val.value = value
end

pro structtest::printValue
print, self.val.value
end

function structtest::getStruct
return, self.val
end

pro structtest__define
obj = { STRUCTTEST , val: {nullableString} }
end
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: HDF5 data
Next Topic: Probability contour plots

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

Current Time: Wed Oct 08 13:40:03 PDT 2025

Total time taken to generate the page: 0.00550 seconds