Re: Dangling Reference
From: Ron Natalie (ron_at_sensor.com)
Date: 10/27/03
- Next message: Rex_chaos: "Re: how to check validity in expression template"
- Previous message: Moonlit: "Re: STRANGE QUESTION : search engine query and web site dowload"
- In reply to: kaede: "Dangling Reference"
- Next in thread: kaede: "Re: Dangling Reference"
- Reply: kaede: "Re: Dangling Reference"
- Reply: kaede: "Re: Dangling Reference"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 27 Oct 2003 12:45:09 -0500
"kaede" <kaedeRukawa_jp@hotmail.com> wrote in message news:60a3ffc9.0310270932.7c6cfc3b@posting.google.com...
>
> When re-running scenerio A - C, the contents of data seems to be
> dumping out
> correctly. I am not sure why?
>
Because one of the insidious features of undefined behavior is that things
might appear to work normally (only to fail later).
In Scenario A, you have it right. The temporary ceases to be as soon
as the constructor finishes.
In Scenario B, you have undefined behavior. What happens if you
change the member of data after holder is constructed but before
you print? I suspect either that you are benefiting from the eliding
of the temporary or somehow the reference ends up seated at the
variable in main. In either case it's just a conincidence.
Scenario C, you don't have undefined behavior. There is no temporary.
The reference in holder refers to the variable data in main. It lives longer
than holder does in fact.
In Scenario D, you just get more coincidental behavior, but you've changed
the data object's size so that it's really small and may end up being parked
in a register.
- Next message: Rex_chaos: "Re: how to check validity in expression template"
- Previous message: Moonlit: "Re: STRANGE QUESTION : search engine query and web site dowload"
- In reply to: kaede: "Dangling Reference"
- Next in thread: kaede: "Re: Dangling Reference"
- Reply: kaede: "Re: Dangling Reference"
- Reply: kaede: "Re: Dangling Reference"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|