Re: static struct definition
On Monday, 27 August 2012 at 18:53:23 UTC, bearophile wrote: Andrej Mitrovic: Isn't this limited to just classes? See the last section of this page: http://dlang.org/struct.html Nested Structs: A nested struct is a struct that is declared inside the scope of a function or a templated struct that has aliases to local functions as a template argument. Nested structs have member functions. It has access to the context of its enclosing scope (via an added hidden field). Bye, bearophile From TDPL: 7.18: Unlike classes nested within classes, nested structs and nested classes within structs don’t contain any hidden member outer—there is no special code generated. The main design goal of nesting such types is to enforce the desired access control. I suppose this has become obsolete then? ...Or is it the other way around?
Re: static struct definition
On Tue, 28 Aug 2012 12:10:47 +0200, monarch_dodra monarchdo...@gmail.com wrote: From TDPL: 7.18: Unlike classes nested within classes, nested structs and nested classes within structs don’t contain any hidden member outer—there is no special code generated. The main design goal of nesting such types is to enforce the desired access control. I suppose this has become obsolete then? ...Or is it the other way around? TDPL trumps most everything else, I believe. -- Simen
Re: static struct definition
On Tuesday, 28 August 2012 at 11:06:51 UTC, Simen Kjaeraas wrote: On Tue, 28 Aug 2012 12:10:47 +0200, monarch_dodra monarchdo...@gmail.com wrote: From TDPL: 7.18: Unlike classes nested within classes, nested structs and nested classes within structs don’t contain any hidden member outer—there is no special code generated. The main design goal of nesting such types is to enforce the desired access control. I suppose this has become obsolete then? ...Or is it the other way around? TDPL trumps most everything else, I believe. Well, at the same time, the reason I asked is because Andrei told me to declare a sub-struct as static in one of my pull requests. Given he's the author of TDPL... Anyways, I'll try to bring him into the conversation from.
static struct definition
What exactly does it mean when you put static in front of a struct _definition_ (not instance) ? EG: static struct S { static struct SS { } } As opposed to struct S { struct SS { } }
Re: static struct definition
monarch_dodra: What exactly does it mean when you put static in front of a struct _definition_ (not instance) ? EG: static struct S { static struct SS { } } As opposed to struct S { struct SS { } } For the outer struct S I think it means nothing, it's just the stupid DMD compiler that accepts random qualifiers and attributes. void foo() { static void bar() {} struct struct Spam {} struct Baz {} Baz baz; // static assert(Baz.sizeof == size_t.sizeof); } For the inner structs like Spam it's supposed to mean something. Just like static inner functions like bar() can't refer to variables from the enclosing function, static structs like Spam are like global structs, it's just their name that is visible inside the enclosing function foo. Truly inner structs like Baz should have a hidden pointer field that points to the enclosing struct. In practice I don't remember if this feature is already present in the D front-end. Bye, bearophile
Re: static struct definition
On 8/27/12, bearophile bearophileh...@lycos.com wrote: Truly inner structs like Baz should have a hidden pointer field that points to the enclosing struct. Isn't this limited to just classes?
Re: static struct definition
Andrej Mitrovic: Isn't this limited to just classes? See the last section of this page: http://dlang.org/struct.html Nested Structs: A nested struct is a struct that is declared inside the scope of a function or a templated struct that has aliases to local functions as a template argument. Nested structs have member functions. It has access to the context of its enclosing scope (via an added hidden field). Bye, bearophile