On Friday, 29 August 2014 at 02:10:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote:
In D you just use '.' throughout and it Just > Works(tm).

Unless the property you're accessing is also a pointer property, like sizeof. Then you have to be careful. The below prints 4 then 8 (on 32-bit):

unittest {
    import core.stdc.stdlib : malloc, free;

    struct Foo
    {
        public int bar, baz;
    }

    auto foo = cast(Foo*)malloc(Foo.sizeof);

    import std.stdio;
    writeln(foo.sizeof);
    writeln((*foo).sizeof);

    free(foo);
}

Do pointers have any other cases like this besides 'sizeof'?
I couldn't find a list of pointer properties in the docs (whereas I know
where the list of array properties is).

Reply via email to