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

This topic is 4608 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Try typedef unsigned int (WINAPI *ThreadFuncPtr )( void* );

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by evolutionalTry: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 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.