GC interpreting integer values as pointers

%u e at ee.com
Tue Oct 12 08:16:35 PDT 2010


== Quote from Ivo Kasiuk (i.kasiuk at gmx.de)'s article
> > I added the struct again and also ran without the enclosing X class.
> >
> > With X :
> > no reference
> > ========== reference, ad3fd0, ad3fc0, ad3fa0, ad3f80
> > new uint
> > AA
> > struct
> > uint
> > reference
> >
> > Without X :
> > no reference
> > ========== reference, ad2fd0, ad2fc0, ad2fa0, ad2f80
> > new uint
> ...
> No suprises with the struct.
> And the "Without X" example... I am not sure, with the variables all in
> the current stack frame that might be a special case. What about global
> variables instead:
Actually, those were global variables: I simply commented out the encapsulating
class and constructor.
But I left all the allocation in the main.. would that matter?

> ...
> C c;
> uint r;
> S s;
> uint[int] a;
> uint* p;
> uint[] arr;
> void f() {
>   c = new C("reference");
>   new C("no reference");
>   r = cast(uint) cast(void*) new C("uint");
>   s = S(cast(uint) cast(void*) new C("struct"));
>   a[0] = cast(uint) cast(void*) new C("AA");
>   p = new uint;
>   *p = (cast(uint) cast(void*) new C("new uint"));
>   arr = new uint[1];
>   arr[0] = (cast(uint) cast(void*) new C("array"));
> }
> void main(string[] args) {
>   f();
>   GC.collect();
>   writefln("========== %s, %x, %x, %x, %x, %x",
>            c.s, r, s.r, a[0], *p, arr[0]);
> }
> That gives me (with D2):
> array
> new uint
> no reference
> ========== reference, f74c3e20, f74c3e10, f74c3df0, f74
> c3dd0, f74c3db0
> AA
> struct
> uint
> reference



More information about the Digitalmars-d-learn mailing list