c数组中元素类型不完整

时间:2018-10-24 14:01:03

标签: c pthreads

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

这是文件名的内容。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”

1 个答案:

答案 0 :(得分:2)

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

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

ptf_arguments arguments[num_threads]; // <- HERE