[oclug] References vs Pointers
Stephen M. Webb
stephenw at xandros.com
Thu Jul 3 10:29:10 EDT 2008
On 03/07/08 09:58, Jon Earle wrote:
>
> So, the reference, as received by a function, looks and acts like a
> parameter that was passed by value, but actually refers, or points to, the
> original value? In which case, I would need to treat it as if it were not
> a pointer but a local parameter and apply the address-of operator to get
> the original memory location?
Yes, you need to treat it like the rvalue it is. There is no guarantee a
reference parameter is implemented as a pointer: it's quite possible (in
fact in the example case more than likely) that it's just a register and the
value gets copied in before the function call and copied out after the
function call.
> (Lions in PEI... new movie idea, perhaps? Lazy coder's sloppy code
> unleashes some horrible chain of events upon an unsuspecting population?)
According to the C++ standard, if you invoke undefined behaviour, anything can
happen. Anything. A C++ programmer must avoid any missteps for this reason.
Your next typo could open a rift in the space-time continuum and set upon the
world some dark unspeakable lurking horror. Those kinds of problems can be
difficult to debug.
More information about the OCLUG
mailing list