Exact effects of returning Structs
Era Scarecrow
rtcvb32 at yahoo.com
Fri Aug 27 10:10:19 PDT 2010
I have some experimental code I'm writing, and it seems when i return a structure it is either corrupted, or should be disallowed all together. A postblit is suggested this(this), but since I'm returning a structure that isn't tied to anything else it doesn't need to duplicate it.
Example:
struct A{
int b;
char c[];
}
void fun1() {
A a;
a = fun2();
//array a.c corrupted, causes range exception
//int a.b corrupted?!?
}
A fun2(){
A t;
t.c.length = 100;
/*do something*/
return t; //valid before returning.
}
More information about the Digitalmars-d-learn
mailing list