2

I was playing around with pointers and references in Rust and noticed you can create a pointer-to-pointer or reference-to-reference in a single expression:

let i = 0;
let irr = &(&i);
let ipp: *const *const i32 = &(&i as *const i32);

If I was to try something similar in C, I would get a compile error because the 'addressof' operator returns an rvalue which doesn't have a storage location so cannot be pointed to:

int i = 0;
int *ip = &i;
int **ipp = &ip;
int **ipp = &(&i); /* error: cannot take the address of an rvalue of type 'int *' */

How does Rust deal with the intermediate pointer/reference? Does it silently put it on the stack or is there some other magic going on?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
djrollins
  • 180
  • 1
  • 11
  • I believe your question to already be answered by [Why is it legal to borrow a temporary?](https://stackoverflow.com/q/47662253/155423). If you disagree, please [edit] your question to explain why it is different. – Shepmaster Apr 06 '18 at 14:27
  • 3
    @Shepmaster. Yes, thank you. The specifics of my question were answered by [this answer](https://stackoverflow.com/a/47663168/2996594) on the question you linked – djrollins Apr 06 '18 at 14:32

0 Answers0