您好,我正在做一项作业,我需要使用 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/