警告:从分配不兼容的指针类型 [英] Warning: assignment from incompatible pointer type

查看:144
本文介绍了警告:从分配不兼容的指针类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到得到很多的警告,从兼容的指针类型赋值,而我还没有线索原因。

  myPageFrame pageFrames [numOfFrames]
MYPAGE页[numOfPages]//在for循环
pageFrames [I] .thePage =(myState == HOT(安培;页[I]):NULL);该罪犯// 1

我得到警告任何时候,我尝试做任何事情到pageFrames [I] .thePage

有问题的结构:

  // algo_structs.h
typedef结构{INT页次;} 我的页面;typedef结构{MYPAGE结构MYPAGE *翻动书页;
INT装;
INT lastRef;} myPageFrame;


解决方案

MYPAGE 结构MYPAGE 是不同的类型。你可以通过改变使他们成为同类型结构定义:

  typedef结构{MYPAGE
    INT页次;
} 我的页面;

或者你可以只使用 MYPAGE * 而不是结构MYPAGE *

I get getting a lot of 'assignment from incompatible pointer type' warnings, and I haven't a clue 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 a pageFrames[i].thePage

The structs in question:

//algo_structs.h
typedef struct{

int pageNum;

} myPage;

typedef struct myPage{

struct myPage* thePage;
int loaded;
int lastRef;

} myPageFrame;

解决方案

myPage and struct myPage are different types. You could make them the same type by changing the struct definition to:

typedef struct myPage {
    int pageNum;
} myPage;

or you could just use myPage * instead of struct myPage *.

这篇关于警告:从分配不兼容的指针类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆