哪里可以找到C运算符的操作数的确切要求? [英] Where to find the exact requirement of the operand for C operators?

查看:61
本文介绍了哪里可以找到C运算符的操作数的确切要求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我刚做了以下测试:

1:void main(void){

2:int p = 1 ;

3:int * pp =& p;

4:int c = p * pp;

5:int d = p + pp;

6:}

我使用GCC编译器并得到错误和警告:


t2.c:In函数`main'':

t2.c:4:二进制操作数无效*

t2.c:5:警告:初始化从指针生成整数而没有

cast

t2.c:1:警告:返回类型`main''不是'int''


你可以看到另外操作中的操作数可以是int *但不是

乘法。


我检查了我的<<< C编程语言>> ;,它

操作数没有说什么。是否有关于此类规范的良好网络资源?

Hi,
I just did the following test:
1:void main(void){
2: int p = 1;
3: int* pp = &p;
4: int c = p * pp;
5: int d = p + pp;
6:}
I use GCC compiler and get the error and warning:

t2.c: In function `main'':
t2.c:4: invalid operands to binary *
t2.c:5: warning: initialization makes integer from pointer without a
cast
t2.c:1: warning: return type of `main'' is not `int''

You can see that operands in addition operation can be int* but not
in multiplication.

I checked my <<C programming language>>, it does not say anything on
operands. Is there any good web resource on such specification?

推荐答案

5月7日下午2:18,linq ... @ hotmail .com写道:
On May 7, 2:18 pm, linq...@hotmail.com wrote:



我刚做了以下测试:


1 :void main(void){

2:int p = 1;

3:int * pp =& p;

4: int c = p * pp;
Hi,
I just did the following test:

1:void main(void){
2: int p = 1;
3: int* pp = &p;
4: int c = p * pp;



[snip]

[snip]


你可以看到附加操作的操作数可以是int *但不是<乘法时增加

You can see that operands in addition operation can be int* but not
in multiplication.



当你将地址乘以整数时你会得到什么?

会产生一个地址吗?整数?还有什么吗?

这个数字代表什么?


回答这些问题,你就会明白错误的含义

消息和二进制操作数的一些限制

操作。


HTH

-

Lew

What do you get when you multiply an address by an integer? Is the
result an address? An integer? Something else?
What does such a number represent?

Answer these questions, and you''ll understand the meaning of the error
message and some of the limits of the operands of the binary
operations.

HTH
--
Lew


li **** *@hotmail.com 写道:
li*****@hotmail.com wrote:

1:void main(void){

2:int p = 1;

3:int * pp =& p;

4:int c = p * pp;

5:int d = p + pp;

6:}
1:void main(void){
2: int p = 1;
3: int* pp = &p;
4: int c = p * pp;
5: int d = p + pp;
6:}


t2.c:在函数`main''中:

t2.c:4:无效操作数到二进制*
t2.c: In function `main'':
t2.c:4: invalid operands to binary *



n869,6.5.5:每个操作数[到乘法运算符,

即*和/]应具有算术类型。 pp是一个指针,并且确实没有算术类型的
;你的代码违反约束条件。

n869, 6.5.5: "Each of the operands [to the multiplicative operators,
i.e. * and /] shall have arithmetic type." pp is a pointer and does
not have arithmetic type; your code exhibits a constraint violation.


t2.c:5:警告:初始化从指针生成整数而没有

cast
t2.c:5: warning: initialization makes integer from pointer without a
cast



n869,6.5.6:另外,两个操作数都应具有算术类型,或者一个操作数应该是指向对象的指针类型和

其他应具有整数类型。你的代码符合这个约束条件,但

p + pp的结果是指针,而不是整数;因此警告。

另外,pp + 1并不指向一个对象,但幸运的是

对你来说指针可能指向一个数组对象的末尾,所以

你没事。

n869, 6.5.6: "For addition, either both operands shall have arithmetic
type, or one operand shall be a pointer to an object type and the
other shall have integer type." Your code meets this constraint, but
the result of p+pp is a pointer, not an integer; hence the warning.
Additionally, pp+1 does not point to an object, although fortunately
for you a pointer may point one past the end of an array object, so
you are ok.


t2.c:1:警告:返回类型`main''不是'int''
t2.c:1: warning: return type of `main'' is not `int''



不要忽略此警告。

Do not ignore this warning.


我检查了我的<<< C编程语言>> ,它没有在

操作数上说什么。这样的规范有没有好的网络资源?
I checked my <<C programming language>>, it does not say anything on
operands. Is there any good web resource on such specification?



Google提供n869的副本,这是

标准的免费草稿。


-

C. Benson Manica |我*应该*知道我在说什么 - 如果我

cbmanica(at)gmail.com |不,我需要知道。火焰欢迎。

Google for a copy of n869, which is a freely available draft of the
standard.

--
C. Benson Manica | I *should* know what I''m talking about - if I
cbmanica(at)gmail.com | don''t, I need to know. Flames welcome.


Lew Pitcher在05/07/07 14:35写道:
Lew Pitcher wrote On 05/07/07 14:35,:

5月7,下午2:18,linq ... @ hotmail.com写道:
On May 7, 2:18 pm, linq...@hotmail.com wrote:

>>
我刚做了以下测试:

1:void main(void){
2:int p = 1;
3:int * pp =& p;
4:int c = p * pp;
>>Hi,
I just did the following test:

1:void main(void){
2: int p = 1;
3: int* pp = &p;
4: int c = p * pp;



[snip]


[snip]


>您可以看到加法操作中的操作数可以是int *但不是

> You can see that operands in addition operation can be int* but not
in multiplication.




当你将地址乘以整数时你会得到什么?

会产生一个地址吗?整数?还有什么吗?

这个数字代表什么?


回答这些问题,你就会明白错误的含义

消息和二进制操作数的一些限制

操作。



What do you get when you multiply an address by an integer? Is the
result an address? An integer? Something else?
What does such a number represent?

Answer these questions, and you''ll understand the meaning of the error
message and some of the limits of the operands of the binary
operations.



为了获得更多的洞察力,请根据

a机器设置答案,其地址类似于221B Baker Street,

" 1600 Pennsylvania Avenue,"和79 Wistful Vista。


-
Er*********@sun.com


这篇关于哪里可以找到C运算符的操作数的确切要求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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