#include <iostream>
/*
* Where in this program are we accessing the _stored value_
* of `b.y` through something other than a glvalue of type int?
* */
struct A { int x; };
struct B { int y; } b { 1024 };
int main () {
A * ptr = reinterpret_cast<A*> (&b); // (1), same value representation/alignment, guaranteed.
int& ref = (*ptr).x; // (2), not accessing the _stored value_ of anything,
// merely forming a reference to an object
int val = ref; // (3), accessing `b.y` through a glvalue of type `int`, safe
}
/*
* NOTE: 2), Just as taking the address of object X does not access the stored value of object X,
* the same thing applies when we are creating a T&; we are referring to an object, not
* the value of said object.
*/
I2luY2x1ZGUgPGlvc3RyZWFtPgoKLyoKICogV2hlcmUgaW4gdGhpcyBwcm9ncmFtIGFyZSB3ZSBhY2Nlc3NpbmcgdGhlIF9zdG9yZWQgdmFsdWVfCiAqIG9mIGBiLnlgIHRocm91Z2ggc29tZXRoaW5nIG90aGVyIHRoYW4gYSBnbHZhbHVlIG9mIHR5cGUgaW50PwogKiAqLwoKc3RydWN0IEEgeyBpbnQgeDsgfTsKc3RydWN0IEIgeyBpbnQgeTsgfSBiIHsgMTAyNCB9OwoKaW50IG1haW4gKCkgewogIEEgICogcHRyID0gcmVpbnRlcnByZXRfY2FzdDxBKj4gKCZiKTsgLy8gKDEpLCBzYW1lIHZhbHVlIHJlcHJlc2VudGF0aW9uL2FsaWdubWVudCwgZ3VhcmFudGVlZC4KCiAgaW50JiByZWYgPSAoKnB0cikueDsgLy8gKDIpLCBub3QgYWNjZXNzaW5nIHRoZSBfc3RvcmVkIHZhbHVlXyBvZiBhbnl0aGluZywKICAgICAgICAgICAgICAgICAgICAgICAvLyAgICAgIG1lcmVseSBmb3JtaW5nIGEgcmVmZXJlbmNlIHRvIGFuIG9iamVjdAoKICBpbnQgdmFsID0gcmVmOyAgICAgICAvLyAoMyksIGFjY2Vzc2luZyBgYi55YCB0aHJvdWdoIGEgZ2x2YWx1ZSBvZiB0eXBlIGBpbnRgLCBzYWZlCn0KCi8qCiAqIE5PVEU6IDIpLCBKdXN0IGFzIHRha2luZyB0aG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