Exact effects of returning Structs

Era Scarecrow rtcvb32 at yahoo.com
Fri Aug 27 13:04:50 PDT 2010


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Era Scarecrow:
> >   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.
> If possible please show a complete minimal program that contains a main() that
shows your problem.

 I know i've been going a different route with the code since so i am not sure
where exactly it was, and can't duplicate the problem now.

 However single-lining through it brings up a question of assumption. Aren't
array's (dynamic and otherwise) filled with 0's by default?

Str_BigNum add(in Str_BigNum rhs) {
	Str_BigNum tmp;
	char res[];
	res.length = _result.length + 1;
	res[1 .. $] = _result[];
//res[0] should be null, right??
	_addsub!("+")(res, rhs._result);
	tmp._result = res;
	return tmp;
}


More information about the Digitalmars-d-learn mailing list