On Wednesday 21 January 2015 00:12:22 Anton Lundin wrote:
> > Useless trivia (and at the risk of making Dirk and Linus hate C++ even
> > more):  passing a C++ static method as a callback to a C function is not
> > standards- compliant. The callback should be a non-member static function
> > inside an extern "C" block.
> >
> > 
> >
> > No, don't do that. This is useless.
> 
> But how would you do the cast to get the object to execute the callback
> on then?

The extern "C" function can call the C++ function. So taken from QtDBus:

extern "C"{
static void qDBusResultReceived(DBusPendingCall *pending, void *user_data)
{
    QDBusPendingCallPrivate *call = reinterpret_cast<QDBusPendingCallPrivate 
*>(user_data);
    Q_ASSERT(call->pending == pending);
    Q_UNUSED(pending);
    QDBusConnectionPrivate::processFinishedCall(call);
}
}

void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate 
*call)
{
        [...]
}

> //Anton - Who cursed at c++ for not accepting designated initializers..

Yeah... I think I asked once about this but I don't remember the rationale. 
Probably conflicts with the uniform initialisation syntax and initializer_list.

However, we had a good discussion on allowing this together with reorderable 
parameters.

void f(int a, int b);
struct S { int c, d; };
struct SC { SC(int c, int d); };

f(.b = 1, .a = 2);              equivalent to:          f(2, 1);
S{.d = 4, .c = 3};                                              S{3, 4}
SC{.d = 4, .c = 3};                                             SC{3, 4};

But no one wrote a paper to submit to the committee... well, we have a few 
years left before C++17.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to