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
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
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