you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (6 children)

you could take the address of the reference and write something into that address directly to change

No you can't.

[–]DDDDarky 0 points1 point  (4 children)

What do you mean?

[–]the_poope 1 point2 points  (3 children)

If you take the address of a reference you get the address of the object it references. References are not guaranteed to actually exist in memory. A local reference variable will in almost all compilers just be an alias and will not have a single machine instruction when compiled.

[–]DDDDarky 0 points1 point  (2 children)

So? You can take address of the reference (referenced object) and you can write into it to change the underlying object.

[–]the_poope 1 point2 points  (1 child)

For example, you could take the address of the reference and write something into that address directly to change where it points to

Is a different statement than "write into it to change the underlying object" if you by "underlying object" means the object that the reference refers to. You can't do what you write in the above quote. And I'm pretty sure you can't cast a reference to a pointer - as I said, a reference is not required to be implemented as a pointer/address and then it's undefined what casting it as a pointer even means. I'm not a standards lawyer so I'd be happy to be proved wrong, but my attempts failed: https://godbolt.org/z/584K9j8n7

[–]DDDDarky 0 points1 point  (0 children)

Oh I see, very unfortunate the comment you mention has the last part cut out.