potential behavior of nested structs

Maxim Fomin maxim at maxim-fomin.ru
Sun Feb 3 23:15:46 PST 2013


On Monday, 4 February 2013 at 00:26:10 UTC, Era Scarecrow wrote:
>  Branched off since this seems appropriate.
>
>  Currently nested structs are illegal, since having them on the 
> stack passing them with a context pointer would result in 
> illegal code or undefined behavior.

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.

>  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


More information about the Digitalmars-d mailing list