Re: [Quickfix-developers] Confused by possible bug in Utility.cpp / thread_spawn
Brought to you by:
orenmnero
From: Djalma R. d. S. F. <drs...@gm...> - 2013-01-22 19:52:37
|
On Tue, Jan 22, 2013 at 4:38 PM, K. Frank <kfr...@gm...> wrote: > "func" in the thread_spawn call is a formal argument (that > happens to be a pointer to a function), and is stored on > the stack when thread_spawn is called. "func" is not a > function, in the technical sense that "f" is a function in the > example above. So &func is the address on the stack where > the value of the argument func is stored. &func and func > are not the same, and (if you want a pointer to a pointer) > there is nothing optional about the '&'. > Well, I think you are correct here. Indeed, if you get the function pointer declaration in utility.h it is missing the expected * just after _stdcall, but the compiler does not care. #ifdef _MSC_VER typedef unsigned int (_stdcall THREAD_START_ROUTINE)(void *); After fixing the declaration, typedef unsigned int (_stdcall *THREAD_START_ROUTINE)(void *); and trying to use &func the compiler starts to complain as expected, although with a weired error message. 1>.\Utility.cpp(517) : error C2664: '_beginthreadex' : cannot convert parameter 3 from 'FIX::THREAD_START_ROUTINE *' to 'unsigned int (__cdecl *)(void *)' I believe that for some kind of magic behind the scenes (that I definitively would not dare to try to explain), everything works fine and the compiler currently generates the correct code for Windows platform. It is really very confusing issue. Unfortunately I don't have VC11/VC12 at the momento to check whether this is something that was fixed in newer versions of Microsoft compiler. |