Visual Studio C ++ 2008
我正在使用线程。但是,我有这个警告,不知道我做错了什么。
1. unsigned int (__stdcall *)(void *) differs in levels of indirection from 'void *(__stdcall *)(void *)'
2. _beginthreadex different types for formal and actual parameters 3
/* Function prototype */
void* WINAPI get_info(void *arg_list)
DWORD thread_hd;
DWORD thread_id;
/* Value to pass to the function */
int th_sock_desc = 0;
/* Create thread */
thread_hd = _beginthreadex(NULL, 0, get_info, (void*) th_sock_desc, 0, &thread_id);
if(thread_hd == 0)
{
/* Failed to create thread */
fprintf(stderr, "[ %s ] [ %s ] [ %d ]\n", strerror(errno), __func__, __LINE__);
return 1;
}
答案 0 :(得分:1)
传递给_beginthreadex
的Thread函数的原型与传递给_beginthread
uintptr_t _beginthread(
void( *start_address )( void * ),
unsigned stack_size,
void *arglist
);
uintptr_t _beginthreadex(
void *security,
unsigned stack_size,
unsigned ( *start_address )( void * ),
void *arglist,
unsigned initflag,
unsigned *thrdaddr
);
与CreateThread
期望的内容相同,
DWORD WINAPI ThreadProc(
__in LPVOID lpParameter
);
因此您需要将线程proc的函数签名更改为
unsigned WINAPI get_info(void *arg_list)
删除更改返回类型。 WINAPI
和
实际上需要WINAPI,文档显示_beginthredex的错误原型,但他们明确声明需要__stdcall。你的问题只是返回类型。此外,错误消息表示__stdcall是预期的,因此可以解决它。