Search code examples
cpointersstructured

How to convert a structure to a C pointer in D?


How do I convert a D structure to a C Pointer in D? Something like:

struct test {}
void main() {
    auto testv = test();
    randomfunction(cast(cPtr) test);
}

Solution

  • If you just want to pass the struct's address to the function, use the & (address-of) operator to get a pointer to a structure variable:

    randomFunction(&testv);