Sign in to follow this  
Red Ant

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

Recommended Posts

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??

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this