Skip to main content
6 events
when toggle format what by license comment
May 18, 2016 at 18:30 comment added D. Jurcau It's a feature introduced in the C++ standard, § 5.1.2 The closure type for a non-generic lambda-expression with no lambda-capture has a public non-virtual nonexplicit const conversion function to pointer to function with C++ language linkage (7.5) having the same parameter and return types as the closure type’s function call operator. The value returned by this conversion function shall be the address of a function that, when invoked, has the same effect as invoking the closure type’s function call operator
May 18, 2016 at 18:15 comment added Loki Astari The type of the third parameter is: LPTHREAD_START_ROUTINE which is DWORD (__stdcall *) (LPVOID lpThreadParameter). On the other hand lambda's have there own type that is not convertable to that type. So no they can't be called. If it does work it is querk of the ABI and unlikely to continue working long term.
May 18, 2016 at 18:06 comment added Loki Astari @D.Jurcau: Undefined behavior can look like its working. Does not make it any more valid. This static_cast<DWORD(__stdcall *)(LPVOID)>([](LPVOID parameter){}) just makes me cry blood.
May 18, 2016 at 14:46 comment added D. Jurcau Sure you can. Here's a proof-of-concept: pastebin.com/XwEW4L9F Under VS 2015 it works even without the cast to the function pointer.
May 18, 2016 at 13:48 comment added Loki Astari Can't pass lambda to CreateThread(). It must be An application-defined function See: msdn.microsoft.com/en-us/library/windows/desktop/…
May 18, 2016 at 7:48 history answered D. Jurcau CC BY-SA 3.0