这个问题是关于线程提出的,但我有一个更简单的案例。(初学者)
我在不同的编译器中尝试了 C++ 的代码,但不起作用。
请告知如何替换该行: callback = (void*)myfunc;//-->error
typedef struct _MyMsg {
int appId;
char msgbody[32];
} MyMsg;
void myfunc(MyMsg *msg)
{
if (strlen(msg->msgbody) > 0 )
printf("App Id = %d \n Msg = %s \n",msg->appId, msg->msgbody);
else
printf("App Id = %d \n Msg = No Msg\n",msg->appId);
}
/*
* Prototype declaration
*/
void (*callback)(void *);
int main(void)
{
MyMsg msg1;
msg1.appId = 100;
strcpy(msg1.msgbody, "This is a test\n");
/*
* Assign the address of the function 'myfunc' …Run Code Online (Sandbox Code Playgroud)