digitalmars.D.learn - Static fields with shared fields
- Marcel (7/7) Jan 27 2020 Hello!
- Steven Schveighoffer (7/13) Jan 27 2020 I would say the type itself would have to be shared. You can (I think)
Hello! If I declare a static variable inside a struct that contains a shared field, is that new variable also shared? For example, say I have a custom atomic wrapper type, like C++'s std::atomic<T>, that contains only one shared variable: Does it remain shared when I instantiate one or do I have to rely on shared again (or __gshared)?
Jan 27 2020
On 1/27/20 5:39 PM, Marcel wrote:Hello! If I declare a static variable inside a struct that contains a shared field, is that new variable also shared? For example, say I have a custom atomic wrapper type, like C++'s std::atomic<T>, that contains only one shared variable: Does it remain shared when I instantiate one or do I have to rely on shared again (or __gshared)?I would say the type itself would have to be shared. You can (I think) declare shared types, which are automatically shared even without declaring the variable shared. At least, it used to be that way. Note that anything you declare shared can be shared. So even if you can't share the enclosing struct, you can share the member. -Steve
Jan 27 2020