c 数组中的不完整元素类型

标签 c pthreads

您好,我正在做一项作业,我需要使用 pthreads 处理一些图像(调整大小)。

这是filename.h的内容

typedef struct {
    int type;
    int width;
    int height;
    int max_value;
    int *input;
    int *output;
}image;

typedef struct {
    int id; // thread id
    image *in; //input image
    image *out; // output image
}ptf_arguments;

这是filename.c文件的内容

    void resize(image *in, image * out) { 
    int i;
    // printf("Type is %d. We have width = %d and height = %d. Max value is %d\n", in->type, in->width, in->height, in->max_value);
    pthread_t tid[num_threads];
    struct ptf_arguments arguments[num_threads]; // <- HERE
    for(i = 0 ; i < num_threads; i++) {
        arguments[i].id = i;
        arguments[i].in = in;
        arguments[i].out = out;
    }
    printf("First thread should have id = %d. In image of (%d)\n", args[0].id, arguments[0].in.width);
    for(i = 0 ; i < num_threads; i++) {
        //pthread_create(&(tid[i]), NULL, resize_thread_function, &(args[i]));
    }
}

我收到这个错误:

 error: array type has incomplete element type ‘struct ptf_arguments’
     struct ptf_arguments arguments[num_threads];

在 <- HERE 注释标记的行 编译命令是:

gcc -o filename filname.c -lpthread -Wall -lm

这是怎么回事,我该如何解决?谢谢

编辑 1:是的,我做了 #include "filename.h"

最佳答案

ptf_arguments 符号不是结构,它是类型名(类型别名)。作为类型名称,它可以用作任何其他类型(例如 int)。

要解决您的错误,请删除声明的 struct 部分:

ptf_arguments arguments[num_threads]; // <- HERE

关于c 数组中的不完整元素类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52970964/

相关文章:

c - 如何释放指针数组?

c - 将两个或多个线程组合在一起

pthreads - pthread_exit(PTHREAD_CANCELED) 和 pthread_cancel(pthread_self()) 之间的区别

c++ - 使用 C++ 从 MJPEG 流中捕获视频

c 函数返回 2 个值,但仅将 1 个传递给语句

c - 打开 bundle 中的文件时,fgetpos 在 iOS 6.1 模拟器中失败

c - C 中的后缀增量和前缀运算符

c - 如何判断哪个pthread唤醒了pthread? C

c - 在单个 Pthread 中打印

Linux多线程编程,原子代码区域