Re: not expected pointers for struct members from foreach

2012-10-10 Thread deed
Struct pointers are useful and reliable, but before using them you need to know the difference between heap and stack, what a stack frame is, and how structs are handled when they are on the stack. Learning the basics of such things ideas requires only few minutes and it will be useful for many

Re: not expected pointers for struct members from foreach

2012-10-09 Thread bearophile
deed: Meaning struct pointers are unusable or at least highly unreliable? Struct pointers are useful and reliable, but before using them you need to know the difference between heap and stack, what a stack frame is, and how structs are handled when they are on the stack. Learning the basics

Re: not expected pointers for struct members from foreach

2012-10-09 Thread H. S. Teoh
On Wed, Oct 10, 2012 at 12:59:08AM +0200, deed wrote: > On Tuesday, 9 October 2012 at 16:21:47 UTC, bearophile wrote: > >deed: > > > >> // Again, why are the three last adresses the same? > > > >The D language and its compiler is acting correctly here, so the > >output you see is correct. All

Re: not expected pointers for struct members from foreach

2012-10-09 Thread deed
On Tuesday, 9 October 2012 at 16:21:47 UTC, bearophile wrote: deed: // Again, why are the three last adresses the same? The D language and its compiler is acting correctly here, so the output you see is correct. All those structs are allocated on the stack. The first three Test are a

Re: not expected pointers for struct members from foreach

2012-10-09 Thread bearophile
deed: // Again, why are the three last adresses the same? The D language and its compiler is acting correctly here, so the output you see is correct. All those structs are allocated on the stack. The first three Test are allocated on the stack. In the loop it allocates the first str

not expected pointers for struct members from foreach

2012-10-09 Thread deed
import std.stdio; struct Test { static Test[] objects; static Test*[] psObject; static int[] ints; static int*[] psInt; int a; int b; int* pa; this(int a) { this.a = a; this.pa = &this.a; this.b = 2 * a;