digitalmars.D.learn - Trying to understand a simple piece of code: dmd barray
- Dibyendu Majumdar (10/10) Mar 07 2020 Hi,
- drug (3/20) Mar 07 2020 it comes from `array` being alias for `this`, see above
- Steven Schveighoffer (8/21) Mar 07 2020 To expand on this, the compiler basically substitutes the symbol aliased...
- Dibyendu Majumdar (4/14) Mar 07 2020 Hmm should not that change the meaning of this throughout the
- Steven Schveighoffer (7/22) Mar 07 2020 No, it's simply a fallback. If the symbol doesn't work with this.symbol,...
- Dibyendu Majumdar (3/6) Mar 07 2020 Okay thank you.
- Ferhat =?UTF-8?B?S3VydHVsbXXFnw==?= (4/18) Mar 07 2020 This is also a way of imitating inheritance in c-ish code without
Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this; 2. The struct has no property called length - but this is referenced. Where does this come from? Thank you Regards
Mar 07 2020
07.03.2020 15:05, Dibyendu Majumdar пишет:Hi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this;This means that `array` can be used instead of `this`2. The struct has no property called length - but this is referenced. Where does this come from?it comes from `array` being alias for `this`, see aboveThank you Regards
Mar 07 2020
On 3/7/20 7:26 AM, drug wrote:07.03.2020 15:05, Dibyendu Majumdar пишет:To expand on this, the compiler basically substitutes the symbol aliased here for the item itself if all other members are a compiler error. So for example, if you have: barr.length; and barr has no member length, it tries: barr.array.length -SteveHi, I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this;This means that `array` can be used instead of `this`
Mar 07 2020
On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote:Hmm should not that change the meaning of this throughout the struct? is this good practice? Thank youI am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this;This means that `array` can be used instead of `this`
Mar 07 2020
On 3/7/20 8:06 AM, Dibyendu Majumdar wrote:On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote:No, it's simply a fallback. If the symbol doesn't work with this.symbol, try this.array.symbol. It's D's version of implicit conversion. You can make the alias this a no-arg function and it will try calling that function. -SteveHmm should not that change the meaning of this throughout the struct? is this good practice?I am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this;This means that `array` can be used instead of `this`
Mar 07 2020
On Saturday, 7 March 2020 at 14:33:29 UTC, Steven Schveighoffer wrote:It's D's version of implicit conversion. You can make the alias this a no-arg function and it will try calling that function.Okay thank you.
Mar 07 2020
On Saturday, 7 March 2020 at 13:06:39 UTC, Dibyendu Majumdar wrote:On Saturday, 7 March 2020 at 12:26:32 UTC, drug wrote:This is also a way of imitating inheritance in c-ish code without classes.Hmm should not that change the meaning of this throughout the struct? is this good practice? Thank youI am trying to understand https://github.com/dlang/dmd/blob/master/src/dmd/backend/barray.d. Two questions: 1. What does this mean and why is it needed? line 95: alias array this;This means that `array` can be used instead of `this`
Mar 07 2020