On 10/25/22 17:16, Salih Dincer wrote:

> Excuse me, but they still write in purple prose about dynamic&static
> array literature here!

I've heard positive things about D's arrays from people who use D in production. Especially slices...

> I've known D for more than 10 years, but the topic we're talking about
> still seems strange to me.

Your example makes it more complicated and potentially exposes a bug.

> The explanations given are not enough for
> me, I'm sorry.

There may be a number of different concepts to list but I don't think there is anything inherently complicated with these topics (again, your example is more complicated).

> Can anyone tell me what happens when I change the location of the
> structure?

What you mean is, you see different behaviour depending on struct X is nested or not. The difference is, nested structs carry a context pointer. This may be related to a bug for the different outputs that we see.

> So the X structure must be in the stack when it is in
> main(), and the following must be in the heap, right?

To nit-pick: The struct is just a definition. Not the struct but its objects can be on the stack or on the heap.

But yes, all objects you have are on the stack.

> //void main() {

So when you uncomment that line and comment-out the following main() line in the program, you see a different output.

I tested: If you make X a 'static struct', then you see the same output.

I think the difference is due to a bug.

Ali

Reply via email to