[Issue 8545] defined opCast disables cast(void*)this in classes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 14 03:21:58 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8545


art.08.09 at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |art.08.09 at gmail.com


--- Comment #4 from art.08.09 at gmail.com 2012-08-14 03:21:53 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> > I don't think this is major, because you can use a union:
> > 
> > {
> >     static union U { Object o; void* p; }
> >     U u;
> >     u.o = this;
> >     return u.p;
> > }
> > 
> > In fact, because a union can be used for reinterpret casting, I don't think any
> > new syntax or semantics are needed.
> 
> I'm speaking in terms of wrapping C++ libraries (A C++ wrapper class has an
> inner d_object pointer which it uses to invoke D virtual methods). You're
> asking me to introduce overhead for every time a new class object is
> instantiated.

The compiler /should/ handle it w/o any additional runtime overhead. You could
also use

    void* test() { return *cast(void**)&this; }

Which approach will be more efficient probably depends on compiler
implementation; ideally both versions should be free.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list