【发布时间】:2013-11-23 21:05:15
【问题描述】:
我正在用 C 语言编写图形的实现。我遇到了一种情况,我无法弄清楚编译器出现指针类型转换警告的行为方式的原因。 这是结构;
#define MAXV 10
typedef struct {
int y;
int weight;
struct edgenode *next;
} edgenode;
typedef struct {
edgenode *edge[MAXV+1];
int degree[MAXV+1];
// other info of graph
} graph;
// operation in some other function
p->next = g->edge[x];
当我执行这种操作时,我收到了一个指针类型转换警告[默认启用]。
即使在尝试对所有可能的演员进行类型转换后,我也无法删除此警告。
最后我对结构进行了代码更改,突然警告消失了。
结构代码更改是这样的:-
typedef struct edgenode { // note that I have added structure name here
// same as above definition
} edgenode;
// operation in some other function
p->next = g->edge[x];
现在警告消失了,代码运行时没有任何警告。
我不明白为什么会发生这种情况;有人可以帮我解决这个问题吗?
【问题讨论】: