【发布时间】:2011-10-24 04:59:36
【问题描述】:
今天再次重新输入..
结构中是指向函数的指针,在这个函数中我希望能够处理来自这个结构的数据,所以指向结构的指针作为参数给出。
这个问题的演示
#include <stdio.h>
#include <stdlib.h>
struct tMYSTRUCTURE;
typedef struct{
int myint;
void (* pCallback)(struct tMYSTRUCTURE *mystructure);
}tMYSTRUCTURE;
void hello(struct tMYSTRUCTURE *mystructure){
puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */
}
int main(void) {
tMYSTRUCTURE mystruct;
mystruct.pCallback = hello;
mystruct.pCallback(&mystruct);
return EXIT_SUCCESS;
}
但我收到警告
..\src\retyping.c:31:5:警告:传递参数 1 来自不兼容指针类型的“mystruct.pCallback” ..\src\retyping.c:31:5:注意:预期的 'struct tMYSTRUCTURE *' 但是 参数的类型为“struct tMYSTRUCTURE *”
预期为 'struct tMYSTRUCTURE *' 但实际上是 'struct tMYSTRUCTURE *',好笑!
任何想法如何解决它?
【问题讨论】:
-
在你的代码中,没有
struct tMYSTRUCTURE这样的东西,它是一个不完整的类型。你所拥有的只是一个 anonymous 结构,它也恰好被类型定义为tMYSTRUCTURE。见stackoverflow.com/questions/612328/…。
标签: c parameters struct type-conversion function-pointers