DIP1000

bauss jj_1337 at live.dk
Wed Jun 29 05:51:26 UTC 2022


On Tuesday, 28 June 2022 at 21:58:48 UTC, Ola Fosheim Grøstad 
wrote:
>
>> not-scoped variable (`a.next` is not `scope` since this 
>> attribute is not transitive)
>
> Well, that is a flaw, if the object is stack allocated then the 
> fields are too.
>

Not necessarily, especially if the fields aren't value types. You 
can have stack allocated "objects" with pointers to heap 
allocated memory (heap allocated "objects".)

You can't, or rather you shouldn't have stack allocated fields 
within heap allocated "objects" however; as that will almost be 
guaranteed to lead to problems. I believe it's possible, but one 
should always refrain from it, but the same isn't true the for 
stack allocated "objects" with heap allocated fields.

Ex. from your example then even if the "node struct" you pass was 
allocated on the stack, then the memory the "next" pointer points 
to might not be allocated same place.

Unless I'm misunderstanding what you're trying to say.


More information about the Digitalmars-d-learn mailing list