“从不兼容的指针类型分配”警告

我正在编写一个函数来解析带有纹理和动画数据的文件,并将其加载到我声明的一些全局结构中。 我在特定行上收到编译器警告“从不兼容的指针类型分配”。 这是很多代码,所以我只想在这里发布重要的部分。

首先,我的动画例程有一个struct数据类型,如下所示:

typedef struct { unsigned int frames; GLuint *tex; float *time; struct animation *next; } animation; 

如您所见,结构中的最后一个变量是指向动画完成时默认为另一个动画的指针。

这是加载函数的声明:

  void LoadTexturePalette(GLuint **texture, animation **anim, const char *filename) 

该函数将信息加载到动画数组中,因此是双指针。

在加载每个动画的最后,从文件中提取一个整数,指示“下一个”指针将指向哪个动画(加载的动画)。

  fread(tmp, 1, 4, file); (*anim)[i].next = &((*anim)[*tmp]); 

在最后一行,我得到编译器警告。 我还没有使用那个变量,所以我不知道警告是否是一个问题,但我觉得我的语法或我的方法在设置该变量时可能是不正确的。

  typedef struct { /* no tag in definition */ unsigned int frames; GLuint *tex; float *time; struct animation *next; /* pointer to an undefined structure */ } animation; 

没有标签( typedef struct animation { /* ... */ } animation; )结构定义中对“struct animation”的任何引用都是对尚未定义的结构的引用。 由于您只使用指向该未定义结构的指针,编译器并不介意。

所以,添加标签—甚至可能摆脱typedef:它只会增加混乱:)

  typedef struct animation { /* tag used in definition */ unsigned int frames; GLuint *tex; float *time; struct animation *next; /* pointer to another of this structure */ } animation;