potential behavior of nested structs

Era Scarecrow rtcvb32 at yahoo.com
Mon Feb 4 04:19:33 PST 2013


On Monday, 4 February 2013 at 07:15:47 UTC, Maxim Fomin wrote:
> Strictly speaking they are not illegal, they just do not have 
> context pointer which points to enclosing struct. Thus, even if 
> you manage to return outer struct data from inner, this would 
> not work if nested struct is created alone, without outer 
> struct.

  I'm aware of that. With nested structs we know they will be part 
of a larger structure so making & using them outside of their 
parent struct just doesn't work; At best you can move them as 
storage but couldn't instantiate them yourself.

>> Thoughts and ideas?
>
> I do not think there are problems with how nested structs with 
> context pointer should be defined. I consider implementation to 
> be a serious problem since we often have <100 messages in forum 
> and no practice steps.
>
> What I expect to be a problem is storing pointer to outer 
> struct in nested struct. The problem is that most structs are 
> stack allocated and stack pointer can be invalidated. Example
> http://d.puremagic.com/issues/show_bug.cgi?id=9352

  Yes I know, this is why returning a struct beyond it's level or 
where it may be invalidated wouldn't be allowed, which combats 
this (or even removes it altogether). But as much as I think on 
the matter of nested structs, I keep coming back to that they are 
an implementation detail of the parent structs and not really 
intended to leave them.


More information about the Digitalmars-d mailing list