[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Operator precedence
Harvey Rarback wrote:
>
> Folks,
>
> I have a couple of questions regarding operator precedence. From this newsgroup
> and some experimentation I believe the following statement is true:
>
> Structure field extraction and array indexing have equal precedence, higher than
> pointer dereference but lower than parentheses to group expressions.
>
> Is this statement true?
>
> So for nested structures struct1.struct2.data produces the same result as
> (struct1.struct2).data as expected. However, for nested objects (example code
> appended) these rules don't seem to apply:
>
> obj1.obj2.data produces an error
> (obj1.obj2).data produces the expected result, along with the infamous
> % Temporary variables are still checked out - cleaning up...
>
> Can some kind soul enlighten me about this behavior?
>
You have found a bug in IDL's object data encapsulation code, which likely
arises from the internal data-storage equivalence of structures and object heap
data.
As David points out, RSI made the (dubious) choice of enforcing full
encapsulation... object instance data is available directly only within the
methods of its class. So by all rights, this should not work at all, and you
should get the error you would have if tried from the command line: "% Object
instance data is not visible outside class methods."
I've found you can access the full data without error or warning if you use two
steps:
o=obj1.obj2
print,o.data
Presumably IDL is getting confused about which type of object it is dealing with
in relation to the method affiliation. Since objects and structures share so
much in common, RSI likely had to append encapsulation functionality with no
doubt some interesting hackery. I strongly recommend against relying on this
feature, since they are quite clear about: "only allowing access to an object's
instance data via that object's methods," and will likely fix it in future
releases. So, like the rest of us, you'll be stuck writing "GetProperty"
methods ... but at least we now have "_REF_EXTRA" for implementing these
correctly.
JD
--
J.D. Smith /*\ WORK: (607) 255-6263
Cornell University Dept. of Astronomy \*/ (607) 255-5842
304 Space Sciences Bldg. /*\ FAX: (607) 255-5875
Ithaca, NY 14853 \*/