On Wednesday, 24 July 2013 at 14:52:53 UTC, monarch_dodra wrote:
On Tuesday, 23 July 2013 at 20:13:33 UTC, John Colvin wrote:
On Tuesday, 23 July 2013 at 17:06:37 UTC, Dicebot wrote:
On Tuesday, 23 July 2013 at 17:03:52 UTC, John Colvin wrote:
Sorry, I should have been more clear. It's the first case that seems weird to me.

Why? '*aptr' is 'a' pretty much by definition of pointer dereferencing.

To be honest, I wasn't expecting foo(*aptr) to compile at all, with a "taking address of temporary" error or similar.

It's clearly the right behaviour to allow it, but it took me by surprise at first.

"Pass-by-Ref" is pretty much sugar for "pass-pointer-by-value".

Basically, if you can take the address of the argument, then passing it is fair game. It's because you can't take the address of a temporary that you can't pass a temporary by ref (unless you are Microsoft Visual Studio, then there's no problem at all apparently 0_o).

Of course, "*aptr" does not return a temporary, so passing that is fair game too.

I'm actually amazed how many years I've had the wrong conception of pointers in my head.

Despite having written *ptr = val a million times, I was still imagining *ptr to be an rvalue i.e. read-from-this-address-and-return-value. How on earth did I never make the connection?!

Reply via email to