[英]error: invalid operands to binary << (have ‘struct str *’ and ‘int’)
How do I make sure that the following program does not cause these errors? 如何确保以下程序不会导致这些错误?
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
error: invalid operands to binary << (have ‘struct EXT_HDR *’ and ‘int’)
My expected output is: 15
我的预期输出是:
15
The code that does this is the following, where I'm using typedef struct
pointer and #define (to get to know the usage). 下面是执行此操作的代码,在这里我使用
typedef struct
指针和#define(以了解用法)。
#include <stdio.h>
typedef struct EXT_HDR {
int sar,rs;
}str;
#define output(O,I) (O |= ((str*)I->sar) | (((str*)I->rs)<<2))
int main(){
int out = 0;
str* val;
val->sar = 3;
val->rs = 3;
output(out,val);
printf("output= %d\n",out);
return 0;
}
You are trying to cast int
to str *
您正在尝试将
int
为str *
((str*)I->rs)
Here you are casting I->rs
to str *
but you meant. 在这里,您将
I->rs
强制转换为str *
但这是您的意思。
((str*)I)->rs
change 更改
#define output(O,I) (O |= ((str*)I->sar) | (((str*)I->rs)<<2))
to 至
#define output(O,I) (O |= (((str*)I)->sar) | (((str*)I)->rs<<2))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.