[C++] typedef trouble --- function pointers

Started by
4 comments, last by SiCrane 18 years, 9 months ago
I believe MS Visual Studio .NET 2003 is playing games with me. :( The following typedef:

typedef unsigned int WINAPI ( *ThreadFuncPtr )( void* );


Produces the following errors: u:\g120tools\dtools\ASTS_versioned\Common\Utils\h\Threading.h(299) : error C2059: syntax error : '(' Strangely the exact same program compiles, links and runs just fine on Dev-C++ 4.9.9.2! Also if I remove the WINAPI from the declaration, the errors go away ... but of course then I get errors elsewhere. What the heck am I doing wrong??? I mean this *is* how you typedef function pointers, isn't it??
Advertisement
Try typedef unsigned int (WINAPI *ThreadFuncPtr )( void* );
Try:
typedef WINAPI unsigned int ( *ThreadFuncPtr )( void* );


The WINAPI dictates the calling convention. You mentioned other errors after removing the WINAPI, what were they?

Edit: ah, yeah - I see what I did wrong
Splendid! Is there any particular reason why it doesn't work the way I did it originally?

P.S. Sicrane's suggestion did the trick.
Quote:Original post by evolutional
Try:

typedef WINAPI unsigned int ( *ThreadFuncPtr )( void* );


The WINAPI dictates the calling convention. You mentioned other errors after removing the WINAPI, what were they?


No, that doesn't work but that's okay. Sicrane has got it right. :)
As to the other errors, they occurred when I was trying to pass my function pointer to beginthreadex, which of course needs a WINAPI-type function pointer as one of its arguments, and since I removed the 'WINAPI', of course that requirement wasn't met anymore.

The reasoning goes like this: the WINAPI is a calling convention specifier, so it binds to the function name. They way you had it originally, the parenthesis separated the calling convention specifier from the function name.

This topic is closed to new replies.

Advertisement