嗨,我正在做一个作业,我需要使用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];
在标有编译命令是:
gcc -o filename filname.c -lpthread -Wall -lm
发生了什么事,我该怎么解决?谢谢你
编辑1:是的,我没有包括“filename.h”
最佳答案
符号ptf_arguments
不是结构,而是类型名(类型别名)。作为类型名,它可以用作任何其他类型(例如int
)。
要解决您的错误,请删除声明的struct
部分:
ptf_arguments arguments[num_threads]; // <- HERE
关于c - c数组中元素类型不完整,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52970964/