C语言 警告:从不兼容的指针类型赋值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20342324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Warning: assignment from incompatible pointer type
提问by user3056261
I keep getting a lot of 'assignment from incompatible pointer type' warnings, and I haven't a clue as to why.
我不断收到很多“从不兼容的指针类型赋值”的警告,但我不知道为什么。
myPageFrame pageFrames[numOfFrames];
myPage pages[numOfPages];
//in a for loop
pageFrames[i].thePage = (myState == HOT ? (&pages[i]) : NULL); // one of the offenders
I get the warning any time I try to do anything to pageFrames[i].thePage.
每当我尝试对pageFrames[i].thePage.
The structs in question are:
有问题的结构是:
//algo_structs.h
typedef struct{
int pageNum;
} myPage;
typedef struct myPage{
struct myPage* thePage;
int loaded;
int lastRef;
} myPageFrame;
回答by R.. GitHub STOP HELPING ICE
myPageand struct myPageare different types. You could make them the same type by changing the structdefinition to:
myPage并且struct myPage是不同的类型。您可以通过将struct定义更改为:
typedef struct myPage {
int pageNum;
} myPage;
or you could just use myPage *instead of struct myPage *.
或者你可以使用myPage *代替struct myPage *.
回答by godel9
You've defined a type called myPage, but you then have a struct member of type struct myPage. You need to be consistent. Here's one way of fixing it:
您已经定义了一个名为 的类型myPage,但是您有一个类型为 的结构体成员struct myPage。你需要保持一致。这是修复它的一种方法:
typedef struct myPage{
myPage* thePage;
int loaded;
int lastRef;
} myPageFrame;

