C 中的编译错误:请求成员“____”不是结构或联合
Compilation Error in C: request for member ‘____’ in something not a structure or union
我收到以下编译错误:request for member ‘threeds’ in something not a structure or union
这是我的结构:
struct pthread_arg {
int size;
int threeds;
int the_threads;
};
这是导致问题的行:
int first = *(arg.threeds) * N/number_of_the_threads;
我在这里查看了其他类似的问题,但在进行建议的更改后仍然出现相同的错误。
看来 arg
是传递给线程函数的参数(它是指向您的结构的指针)。
在那种情况下,您不能直接取消引用 arg
,因为它是 void*
。将其转换为适当的类型(必须匹配传递给 pthread_create API 的参数)然后使用:
void *multiplication(void *arg)
{
struct pthread_arg *myarg = arg;
int first = myarg->threeds * N/number_of_the_threads;
...
我收到以下编译错误:request for member ‘threeds’ in something not a structure or union
这是我的结构:
struct pthread_arg {
int size;
int threeds;
int the_threads;
};
这是导致问题的行:
int first = *(arg.threeds) * N/number_of_the_threads;
我在这里查看了其他类似的问题,但在进行建议的更改后仍然出现相同的错误。
看来 arg
是传递给线程函数的参数(它是指向您的结构的指针)。
在那种情况下,您不能直接取消引用 arg
,因为它是 void*
。将其转换为适当的类型(必须匹配传递给 pthread_create API 的参数)然后使用:
void *multiplication(void *arg)
{
struct pthread_arg *myarg = arg;
int first = myarg->threeds * N/number_of_the_threads;
...