I had a problem with passing a C ++ 0x lambda function as the second argument to makecontext(from ucontext.h). Signatures makecontext:
void makecontext(ucontext_t*, void (*)(), int, ...);
I used to be able to apply C-style casting (void (*)(void))to the global sphere functions that I used. A reinterpret_castwill do the trick in C ++. However, using the C ++ 0x lambda function, I get the following error:
error: invalid cast from type ‘main(int, char**)::<lambda(int)>’ to type ‘void (*)()’
I am using g ++ 4.6. To get a compilation error, the following code is enough:
#include <ucontext.h>
void f1(int i) {}
int main(int argc, char *argv[]) {
ucontext_t c;
makecontext(&c, (void (*)(void))f1, 1, 123);
makecontext(&c, reinterpret_cast<void (*)(void)>(f1), 1, 123);
auto f2 = [](int i){};
makecontext(&c, (void (*)(void))f2, 1, 123);
makecontext(&c, reinterpret_cast<void (*) (void)>(f2), 1, 123);
return 0;
}
source
share