Daniel Jacobowitz wrote: > On Wed, Feb 27, 2008 at 04:08:08PM -0500, Aleksandar Ristovski wrote: >> Another thing that confuses me is such a special treatment for references >> to something... in my mind, (talking about C++) we should be able to >> internally treat them as pointers to that something. I take this back, it looks like we do treat them the way I thought it should. > > value_as_address on a reference is supposed to referenced value as an > address, not the pointer value stored in the reference. It's probably > the caller of value_as_address which is mistaken. > This was the real clue! Thank you for the feedback! Indeed, it appears calling value_as_address is not needed. Once we dereference PTR/REF, we get value representing "the real thing". From there we can fetch address for calculating the offset, and then all works fine. See revisited diff (attached). Also, please find attached the testcase diff, I added check for reference casting. Do I need to provide change log for tests too? NOTE: value_as_address does *not* behave as you described, if passed in a REF to STRUCT, it will coerce_ref, that is ok, but then it will pass coerced value to unpack_long which doesn't know what to do with a STRUCT (which is why I had that confusing code you and Michael complained about). 2008-02-28 Aleksandar Ristovski * eval.c (evaluate_subexp_standard): UNOP_CAST use value_cast_pointers when casting reference to reference. Print error when reference/non-reference mix. * valops.c (value_cast_pointers): Use coerced value to determine address when downcasting.