c - 请求非结构或 union 中的成员 ‘thisWalkno’。 (P线程)

标签 c struct pthreads

我试图将结构中的一些变量放入单独线程中的另一个变量中,但我似乎无法做到这一点。我有一个像这样的结构

typedef struct arguments {
      char thisStart[10];
      char thisWalkno[10];
      char thisMatsize[10]; 
      char thisShmkey[10];
      int *pint;
}arguments;

然后我有了我的 main,在一些初始变量声明之后,我开始将变量放入我的结构中

main ( int argc, char argv[]) {
    arguments tid_arg;
    pthread_t tid;
       .    
       .
       .
       .  


    sprintf(tid_arg.thisWalkno,  "%d", (m + 1));  
    sprintf(tid_arg.thisStart,   "%d", start);  
    sprintf(tid_arg.thisMatsize, "%d", matsize);  
    sprintf(tid_arg.thisShmkey,  "%d", shmkey);

    pthread_attr_init(&attr);
    /* create the thread */
    if (pthread_create(&tid, &attr, tidchild, (void *)&tid_arg) != 0) {
        printf("Could not execute child program\n");
        exit(1);
    } 
     . 
     .
     .
}

最后是我的 tid 子函数

void *tidchild(void *tid_arg) {

    struct arguments *args = tid_arg;
    int walkno, start, shmid, matsize;

    walkno  = atoi(args.thisWalkno);
    pthread_exit(0);
}

当我到达 walkno = atoi(args.thisWalkno) 时,这就是我的错误出现的地方,我似乎无法从结构访问 thisWalkno 。有人可以帮助我吗?

此外,我忘了提及,当我输入 args->thisWalkno 时,我收到“取消引用指向不完整类型的指针”错误。

最佳答案

args 是指向结构体的指针,使用 args->thisWalkno 并且您应该#include struct > 定义在任何需要使用的地方。

关于c - 请求非结构或 union 中的成员 ‘thisWalkno’。 (P线程),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29335956/

相关文章:

c - 使用 getline() 时出现打印问题

ios - 将结构添加到字典中,然后随机调用这些结构

字符数组声明使程序崩溃

c++ - libevent 是否允许在不同的线程中运行定时器/io 的回调?

不使用 malloc 创建动态数组

c - pthread 中的信号处理

linux - 关于pthread_mutex_lock和pthread_mutex_unlock的一些问题

c - 你好,我想在 C 中玩二十一点游戏。当我执行 "deal"函数时,警告“从不兼容的指针类型传递参数”

c++ - 在 C++ 中解析文件

ruby - 使用 rvm 在没有 pthread 的情况下安装 ruby