digitalmars.D.learn - static struct definition
- monarch_dodra (16/16) Aug 27 2012 What exactly does it mean when you put static in front of a
- bearophile (20/36) Aug 27 2012 For the outer struct S I think it means nothing, it's just the
- Andrej Mitrovic (2/5) Aug 27 2012 Isn't this limited to just classes?
- bearophile (5/11) Aug 27 2012 See the last section of this page:
- monarch_dodra (10/21) Aug 28 2012 From TDPL: 7.18:
-
Simen Kjaeraas
(8/17)
Aug 28 2012
On Tue, 28 Aug 2012 12:10:47 +0200, monarch_dodra
- monarch_dodra (5/19) Aug 28 2012 Well, at the same time, the reason I asked is because Andrei told
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 { } }
Aug 27 2012
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
Aug 27 2012
On 8/27/12, bearophile <bearophileHUGS 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?
Aug 27 2012
Andrej Mitrovic:Isn't this limited to just classes?See the last section of this page: http://dlang.org/struct.htmlNested 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
Aug 27 2012
On Monday, 27 August 2012 at 18:53:23 UTC, bearophile wrote:Andrej Mitrovic: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?Isn't this limited to just classes?See the last section of this page: http://dlang.org/struct.htmlNested 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
Aug 28 2012
On Tue, 28 Aug 2012 12:10:47 +0200, monarch_dodra <monarchdodra gmail.co= m> = wrote:From TDPL: 7.18: "Unlike classes nested within classes, nested structs and nested class=es =within structs don=E2=80=99t contain any hidden member outer=E2=80=94there 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
Aug 28 2012
On Tuesday, 28 August 2012 at 11:06:51 UTC, Simen Kjaeraas wrote:On Tue, 28 Aug 2012 12:10:47 +0200, monarch_dodra <monarchdodra gmail.com> wrote: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.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.
Aug 28 2012