Taking the address of an rvalue struct
dsimcha
dsimcha at yahoo.com
Fri Jul 22 08:22:30 PDT 2011
The following code uses the this reference in a struct member function to take
the address of an rvalue struct. Is it well-defined behavior equivalent to
taking the address of a named stack-allocated struct, or is the compiler free
to break it in optimized mode?
struct SomeStruct {
int num;
this(int x) {
num = x;
}
SomeStruct* addressOf() @property {
return &this;
}
}
void main() {
auto ptr = SomeStruct(42).addressOf;
writeln(ptr.num);
}
More information about the Digitalmars-d
mailing list