“来自不兼容指针类型的分配”警告
我正在编写一个函数,它解析带有纹理和动画数据的文件并将其加载到我声明的一些全局结构中。我在特定行上收到编译器警告“来自不兼容指针类型的赋值”。代码很多,所以我只在这里发布重要的部分。
首先,我的动画例程有一个结构数据类型,如下所示:
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]);
在最后一行,我收到编译器警告。我还没有使用该变量,所以我不知道警告是否是一个问题,但我感觉我的语法或方法在设置该变量时可能不正确。
I'm writing a function that parses a file with texture and animation data and loads it into some global structs I have declared. I get the compiler warning "Assignment from incompatible pointer type" on a particular line. It's a lot of code, so I'm just going to post the important parts here.
First, I have a struct datatype for my animation routines, as follows:
typedef struct {
unsigned int frames;
GLuint *tex;
float *time;
struct animation *next;
} animation;
As you can see, the last variable in the struct is a pointer to another animation to default to when the animation is completed.
Here is the declaration of the loading function:
void LoadTexturePalette(GLuint **texture, animation **anim, const char *filename)
The function loads information into an array of animations, hence the double pointer.
At the very end of loading each animation, an integer is pulled from the file that indicates which animation (out of the ones that are loaded) to which the "next" pointer will point.
fread(tmp, 1, 4, file);
(*anim)[i].next = &((*anim)[*tmp]);
On the last line, I get the compiler warning. I'm not yet using that variable, so I don't know if the warning is an issue, but I get the feeling that my syntax or my approach may be incorrect in setting that variable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有标签 (
typedef structanimation { /* ... */ }animation;
),结构体定义中对“structanimation”的任何引用都是对尚未定义的结构体的引用。由于您只使用指向未定义结构的指针,因此编译器不介意。因此,添加标签 --- 甚至可能摆脱 typedef:它只会增加混乱:)
Without the tag (
typedef struct animation { /* ... */ } animation;
) any reference to "struct animation" inside the struct definition is a reference to an, as yet, undefined structure. As you only use a pointer to that undefined structure, the compiler doesn't mind.So, add the tag --- and maybe even get rid of the typedef: it only adds clutter :)