sizeof C积分类型 [英] sizeof C integral types
问题描述
冒险从渥太华的一个汤姆圣丹尼斯调用火焰:)
有没有保证,比如说,
sizeof(int)== sizeof(unsigned int)
sizeof(long)> sizeof(char)?
谢谢,
方舟
Risking to invoke flames from one Tom St Denis of Ottawa :)
Is there any guarantee that, say,
sizeof(int) == sizeof(unsigned int)
sizeof(long) > sizeof(char) ?
Thanks,
Ark
推荐答案
ark写道:
是否有任何保证,比如
sizeof(int)== sizeof(unsigned int)
sizeof(long)> sizeof(char)?
Is there any guarantee that, say,
sizeof(int) == sizeof(unsigned int)
sizeof(long) > sizeof(char) ?
我不相信标准保证两者都是真的。
-
Russell Hanneken
rg ******** @ pobox.com
从我的地址中删除''g'以发送邮件。
I don''t believe the standard guarantees that either is true.
--
Russell Hanneken
rg********@pobox.com
Remove the ''g'' from my address to send me mail.
ark写道:
ark wrote:
是否有任何保证,比如
sizeof(int)== sizeof(unsigned int)
是的。
sizeof(长)> sizeof(char)?
Is there any guarantee that, say,
sizeof(int) == sizeof(unsigned int)
Yes.
sizeof(long) > sizeof(char) ?
编号BTW,sizeof(char)== 1根据定义。
但是,sizeof (长)== 1,我认为这意味着sizeof(int)== 1,
会打破几个非常常见的习语,例如
int ch;
while((ch = getchar())!= EOF){...}
因为EOF应该是一个不同于所有
''unsigned char''值。只有在''int''比''unsigned char''更宽的时候才有可能。
我个人从来没有见过一个程序虽然我认为存在这样的程序,但我担心这可能是b $ b b的可能性。它可能与独立实现不同(实现
不使用C库,所以getchar()没问题)。
-
Hallvard
No. BTW, sizeof(char) == 1 by definition.
However, sizeof(long) == 1, which I think implies sizeof(int) == 1,
would break several very common idioms, e.g.
int ch;
while ((ch = getchar()) != EOF) { ... }
because EOF is supposed to be a value which is different from all
''unsigned char'' values. That is only possible when ''int'' is wider
than ''unsigned char''.
Personally I''ve never seen a program which worred about this
possibility, though I suppose such programs exist. It might
be different with freestanding implementations (implementations
which do not use the C library, so getchar() is no problem).
--
Hallvard
" ark" < AR **** @ comcast.net>写道:
"ark" <ar****@comcast.net> writes:
有没有保证,比如说
sizeof(int)== sizeof(unsigned int)
是。
sizeof(长)> sizeof(char)?
Is there any guarantee that, say,
sizeof(int) == sizeof(unsigned int)
Yes.
sizeof(long) > sizeof(char) ?
No.
-
"您的更正是100%正确的0%有用。干得好!"
- 理查德希思菲尔德
No.
--
"Your correction is 100% correct and 0% helpful. Well done!"
--Richard Heathfield
这篇关于sizeof C积分类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!