Re: Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread xiren7 via Digitalmars-d-learn
Thanks. Ali. My previous post is not clear that I have to store class reference(object pointer) in void*. My actual code is try to use libuv in D. // genarated from uv.h, only two fields is used: 'data', 'type'. // the document of 'data': "Space for user-defined arbitrary data. libuv does not

Re: Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread Ali Çehreli via Digitalmars-d-learn
Hiding a Foo right after Impl can be a solution. However, you need to pass 't', not '&t' to the C function because - Although it may be unexpected, cast(void*) is the specified way of getting the address of a class object - Taking the address of a class reference (which 't' is one), is just

Unexpected behavior when using both alias this and object pointer

2017-01-12 Thread xiren7 via Digitalmars-d-learn
The problem and the code: import std.stdio: writeln; import core.stdc.stdlib: malloc; struct Impl { ubyte[8] payload; } class Foo { Impl *impl; alias impl this; this() { impl = cast(Impl*) malloc(Impl.sizeof); } } class Foo2 { ubyte[8] payload; } void main