通常的算术转换+整体推广简称? [英] Usual arithmetic conversions + integral promotion for short?

查看:56
本文介绍了通常的算术转换+整体推广简称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准兼容的C ++编译器是否有可能具有

(sizeof(短)< sizeof(int))



(sizeof(短)== sizeof((短)0 +(短)0))




问候,


Niels Dekker
http://www.xs4all .nl / ~nd / dekkerware

Is it possible for a standard compliant C++ compiler to have
( sizeof(short) < sizeof(int) )
and
( sizeof(short) == sizeof((short)0 + (short)0) )
?

Regards,

Niels Dekker
http://www.xs4all.nl/~nd/dekkerware

推荐答案



" Niels Dekker(无回复地址)" ; <未***** @ this.is.invalid>在消息中写道

news:40 *************** @ this.is.invalid ...

"Niels Dekker (no reply address)" <un*****@this.is.invalid> wrote in message
news:40***************@this.is.invalid...
是否有可能符合标准的C ++编译器具有
(sizeof(短)< sizeof(int))

(sizeof(短)== sizeof((短)0 +(短)0 ))


该问题的第二部分是*总是*真的!你正在投两个int'的

作为短裤,并将它们加在一起创造临时价值,因此必须是b $ b因此也是短暂的。因此,它自然与大小相同,因为它*是一个短的。


因为第一部分也是真的(或者至少是允许的,

然后......


是的,这是可能的。即使很可能,我也会猜测。


-Howard




问候,

Niels Dekker
http://www.xs4all.nl / ~ndd / dekkerware
Is it possible for a standard compliant C++ compiler to have
( sizeof(short) < sizeof(int) )
and
( sizeof(short) == sizeof((short)0 + (short)0) )
The second part of that question is *always* true! You''re casting two int''s
as shorts, and adding them together to create temporary value, which must
therefore also be a short. So, naturally it has the same size as a short,
because it *is* a short.

And since the first part is also true (or is allowed to be true, at least),
then...

Yes, it is possible. Even probable, I would venture to guess.

-Howard

?

Regards,

Niels Dekker
http://www.xs4all.nl/~nd/dekkerware



Niels Dekker(没有回复地址)写道:
Niels Dekker (no reply address) wrote:
是否有可能标准兼容的C ++编译器有
(sizeof(短)< sizeof(int))

(sizeof(短)== sizeof((短)0 +(短)0) )
Is it possible for a standard compliant C++ compiler to have
( sizeof(short) < sizeof(int) )
and
( sizeof(short) == sizeof((short)0 + (short)0) )
?




后者是强制性的,AFAICT。前者绝对是可能的。


Victor



The latter is mandatory, AFAICT. The former is definitely possible.

Victor


霍华德写的

新闻:gP ** *****************@bgtnsc04-news.ops.worldnet.att.net

comp.lang.c ++:
Howard wrote in
news:gP*******************@bgtnsc04-news.ops.worldnet.att.net in
comp.lang.c++:

Niels Dekker(无回复地址) <未***** @ this.is.invalid>在
消息新闻中写道:40 *************** @ this.is.invalid ...

"Niels Dekker (no reply address)" <un*****@this.is.invalid> wrote in
message news:40***************@this.is.invalid...
是否有可能符合标准的C ++编译器有
(sizeof(短)< sizeof(int))

(sizeof(短)== sizeof((短)0 +(短)0))
Is it possible for a standard compliant C++ compiler to have
( sizeof(short) < sizeof(int) )
and
( sizeof(short) == sizeof((short)0 + (short)0) )



对于OP:


short + short的类型是int(标准整体促销'),

所以答案是否定的。

该问题的第二部分是*永远*真!你正在施放两个
int'作为短裤,并将它们加在一起以创造临时值,
因此也必须是短暂的。因此,它自然与大小相同,因为它*是一个短的。


For the OP:

The type of short + short is int (standard intergral promotion''s),
So the answer is No.

The second part of that question is *always* true! You''re casting two
int''s as shorts, and adding them together to create temporary value,
which must therefore also be a short. So, naturally it has the same
size as a short, because it *is* a short.



#include< iostream>


void f(短)

{

std :: cout<< short \ n;

}


void f(int)

{

std :: cout<< int \ n;

}


int main()

{

短a = 1,b = 2;

f(a + b);

}


如果你得到短 ;在您的编译器上要求退款。


[snip]


Rob。

-
http://www.victim-prime.dsl.pipex.com/


这篇关于通常的算术转换+整体推广简称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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