Passing myself, a struct, as a C callback context
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 29 21:55:14 PDT 2015
On Sun, 29 Mar 2015 22:53:35 -0400, Paul O'Neil wrote:
> I'm registering a callback with some C code. The simplified story is
> here, but the actual code is on GitHub [1] at the end if you care.
>
> The call looks something like this.
>
> void register(void(*fp)(void*), void* context);
>
> I have a class that holds state for the callback and registers itself:
>
> final class Klass {
> void method()
> {
> register(callback_function, &this);
> }
> }
>
> As of dmd 2.067, doing "&this" is deprecated. Is there an idiomatic way
> to do this?
>
> [0] Actual code is at
> https://github.com/todayman/dubik/blob/master/source/vibe/core/drivers/
rx.d#L177
> . The msg object eventually gets passed to the registration function.
>
> Thanks,
you still can cast `this` to void pointer: `cast(void*)this`
but beware of possible `opCast` overloads for `void*` (there are no in
stdlib, but...)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150330/c6fff1b6/attachment-0001.sig>
More information about the Digitalmars-d-learn
mailing list