digitalmars.D.learn - *this
- Paul D. Anderson (7/7) Apr 24 2009 Looking at Don Clugston's BigInt code I see usage of "*this":
- Don (10/22) Apr 24 2009 It's passing by value, since BigInt is a struct, not a class. 'this' is
- Paul D. Anderson (3/28) Apr 24 2009 Thanks, Don.
Looking at Don Clugston's BigInt code I see usage of "*this": BigInt opMulAssign(T: BigInt)(T y) { *this = mulInternal(*this, y); return *this; } I think I know what it does (passes this by reference) but I can't find any documentation that explains the usage. Can anyone point me to a source?? Paul
Apr 24 2009
Paul D. Anderson wrote:Looking at Don Clugston's BigInt code I see usage of "*this": BigInt opMulAssign(T: BigInt)(T y) { *this = mulInternal(*this, y); return *this; } I think I know what it does (passes this by reference) but I can't find any documentation that explains the usage. Can anyone point me to a source?? PaulIt's passing by value, since BigInt is a struct, not a class. 'this' is a pointer to the struct, so *this is the struct itself. In the case of BigInt, the struct only contains an bool and a dynamic array, for a total of 10 bytes or so, so it's not much bigger than a pointer. I believe the behaviour of 'this' in structs changed recently (but probably only in D2?) The BigInt wrapper class would be a bit different in D2. BTW BigInt uses structs, not classes, and part of the reason for this is that you _cannot_ have value semantics with a class.
Apr 24 2009
Don Wrote:Paul D. Anderson wrote:Thanks, Don. PaulLooking at Don Clugston's BigInt code I see usage of "*this": BigInt opMulAssign(T: BigInt)(T y) { *this = mulInternal(*this, y); return *this; } I think I know what it does (passes this by reference) but I can't find any documentation that explains the usage. Can anyone point me to a source?? PaulIt's passing by value, since BigInt is a struct, not a class. 'this' is a pointer to the struct, so *this is the struct itself. In the case of BigInt, the struct only contains an bool and a dynamic array, for a total of 10 bytes or so, so it's not much bigger than a pointer. I believe the behaviour of 'this' in structs changed recently (but probably only in D2?) The BigInt wrapper class would be a bit different in D2. BTW BigInt uses structs, not classes, and part of the reason for this is that you _cannot_ have value semantics with a class.
Apr 24 2009