二进制文件的操作数无效 - [英] Invalid operands to binary -

查看:159
本文介绍了二进制文件的操作数无效 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdlib.h>


int main(无效){

char ** p1;

const char ** p2;


p1 = malloc(5 * sizeof(char *));

如果(p1 == 0)返回EXIT_FAILURE;

p2 = p1 + 1;

p2 - p1;

返回0;

}


当我尝试在gcc 4.1.2上编译上面的内容时,我得到

tc:10:错误:二进制操作数无效 -


这是编译器错误吗?对我来说似乎合法。

#include <stdlib.h>

int main(void) {
char **p1 ;
const char **p2 ;

p1 = malloc(5 * sizeof(char *)) ;
if (p1 == 0) return EXIT_FAILURE ;
p2 = p1 + 1 ;
p2 - p1 ;
return 0 ;
}

When I try to compile the above on gcc 4.1.2 I get
t.c: 10: error: invalid operands to binary -

Is it a compiler bug ? It seems legal to me.

推荐答案

Spiros Bousbouras写道:
Spiros Bousbouras wrote:

#include< stdlib.h>


int main(void){

char ** p1;

const char ** p2;


p1 = malloc(5 * sizeof(char *));

如果(p1 == 0)返回EXIT_FAILURE;

p2 = p1 + 1;

p2 - p1;

返回0;

}

当我尝试在gcc 4.1.2上编译上面的内容时,我得到

tc:10:错误:二进制操作数无效 -


这是编译器错误吗?这对我来说似乎合法。
#include <stdlib.h>

int main(void) {
char **p1 ;
const char **p2 ;

p1 = malloc(5 * sizeof(char *)) ;
if (p1 == 0) return EXIT_FAILURE ;
p2 = p1 + 1 ;
p2 - p1 ;
return 0 ;
}

When I try to compile the above on gcc 4.1.2 I get
t.c: 10: error: invalid operands to binary -

Is it a compiler bug ? It seems legal to me.



我认为它没有错。试试一个gcc论坛

来看看它是否是一个已知的bug?


-

Eric Sosman
es*****@ieee-dot-org.inva


8月8日上午7:42,Spiros Bousbouras< spi ... @ gmail.comwrote:
On Aug 8, 7:42 am, Spiros Bousbouras <spi...@gmail.comwrote:

#include< stdlib .h>


int main(无效){

char ** p1;

const char ** p2;


p1 = malloc(5 * sizeof(char *));

如果(p1 == 0)返回EXIT_FAILURE;

p2 = p1 + 1;

p2 - p1;

返回0;


}


当我尝试在gcc 4.1.2上编译上面的内容时,我得到

tc:10:错误:二进制操作数无效 -


是吗编译器错误?
#include <stdlib.h>

int main(void) {
char **p1 ;
const char **p2 ;

p1 = malloc(5 * sizeof(char *)) ;
if (p1 == 0) return EXIT_FAILURE ;
p2 = p1 + 1 ;
p2 - p1 ;
return 0 ;

}

When I try to compile the above on gcc 4.1.2 I get
t.c: 10: error: invalid operands to binary -

Is it a compiler bug ?



不,它几乎从不是编译器错误。


兼容指针p1和p2之间发生指针减法是
不兼容的类型,不能参与指针减法。你应该在第9行收到警告,你需要投票给

让作业完成。


Robert Gamble

No, it''s almost never a compiler bug.

Pointer subtraction occurs between compatible pointers, p1 and p2 are
incompatible types and cannot participate in pointer subtraction. You
should have received a warning on line 9 as well as you need a cast to
make the assignment work.

Robert Gamble


Spiros Bousbouras写道:
Spiros Bousbouras wrote:

#include< stdlib.h>


int main(无效){

char ** p1;

const char ** p2;


p1 = malloc(5 * sizeof(char *));

如果(p1 == 0)返回EXIT_FAILURE;

p2 = p1 + 1 ;

p2 - p1;

返回0;

}


当我尝试编译时以上关于gcc 4.1.2我得到了

tc:10:错误:二进制操作数无效 -
#include <stdlib.h>

int main(void) {
char **p1 ;
const char **p2 ;

p1 = malloc(5 * sizeof(char *)) ;
if (p1 == 0) return EXIT_FAILURE ;
p2 = p1 + 1 ;
p2 - p1 ;
return 0 ;
}

When I try to compile the above on gcc 4.1.2 I get
t.c: 10: error: invalid operands to binary -



gcc 3.4.4说:


foo.c:在函数main中:

foo.c:9:警告:从不兼容的指针类型分配

foo.c:10:错误:二进制操作数无效 -

gcc 3.4.4 said:

foo.c: In function `main'':
foo.c:9: warning: assignment from incompatible pointer type
foo.c:10: error: invalid operands to binary -


这篇关于二进制文件的操作数无效 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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