digitalmars.D.learn - What does assigning void mean?
- mark (6/6) Mar 04 2020 In Adam Ruppe's D Cookbook there're these lines in a ref counting
- drug (3/10) Mar 05 2020 In D all vars are initialized by default. If you use assigning void then...
- Simen =?UTF-8?B?S2rDpnLDpXM=?= (16/28) Mar 05 2020 To expand a bit on this: You probably don't want to initialize
- mark (3/15) Mar 05 2020 Thanks, I had read it (in "Learning D" I think), but had already
In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please?
Mar 04 2020
On 3/5/20 10:47 AM, mark wrote:In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please?In D all vars are initialized by default. If you use assigning void then the var won't be initialized.
Mar 05 2020
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote:On 3/5/20 10:47 AM, mark wrote:To expand a bit on this: You probably don't want to initialize things with = void - it can lead to hard-to-track bugs and unexpected behavior. The reasons it's there is almost entirely as an optimization - if you know the variable will be initialized elsewhere void initialization ensure things won't be initialized twice when once is enough, and this can be faster. The other use case is when for whatever reason there is no valid default value, but you still want an instance. Probably in order to fill it with data from somewhere else. This would apply e.g. to structs with disabled parameterless constructors whose contents you are reading from disk. In short, when you know you need to void initialize something, that's when you're ready to use it. Kinda like goto. -- SimenIn Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please?In D all vars are initialized by default. If you use assigning void then the var won't be initialized.
Mar 05 2020
On Thursday, 5 March 2020 at 08:35:52 UTC, drug wrote:On 3/5/20 10:47 AM, mark wrote:Thanks, I had read it (in "Learning D" I think), but had already forgotten.In Adam Ruppe's D Cookbook there're these lines in a ref counting example: RefCountedObject o = void; // What does this mean/do? o.data = new Implementation(); o.data.refcount = 1; I don't understand the first line; could someone explain please?In D all vars are initialized by default. If you use assigning void then the var won't be initialized.
Mar 05 2020