Long和Int [英] Long and Int

查看:77
本文介绍了Long和Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我是初学者程序员,我想知道long和int之间的确切差异

。为什么我们有相同大小的两个名称

变量。


各种架构上long和int的大小是否会发生变化..


谢谢,

carl

解决方案

ri ************ @ gmail.com 写道:



我是一个初学者程序员,我想知道long和int之间的确切差异。为什么我们有相同大小的
变量的两个名称。


它们的大小不一定相同。事实上,只有

保证`long`的大小大于或等于

和`int`的大小。

long和int的大小是否会在各种体系结构上发生变化..




有时会这样做,但这也不是必需的。它更多地取决于实际的C实现而不是基础架构。

没有什么能阻止实现64位`long`s
(或者`int`s,就此而言),即使在6位机器上也是如此。


-

BR,Vladimir


我在刮!我正在刮胡子!


" Vladimir S. Oka" <无**** @ btopenworld.com>写道:

[...]只保证`long`的大小大于或等于`int`的大小。



您的意思是范围,而不是大小。 int的范围是

的子范围。关于int和long的大小

没有这样的保证。

-

int main(void){char p [] = " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz。\

\ n",* q =" kl BIcNBFr.NKEzjwCIxNJC" ;; int i = sizeof p / 2; char * strchr(); int putchar(\

); while(* q){i + = strchr(p,* q ++) - p; if(i> =(int)sizeof p)i- = sizeof p-1; putchar(p [i] \

);}返回0;}




ri ************ @ gmail.com 写于02/22/06 18:07 ,:



我是一个初学者程序员,我想知道long和int之间的确切差异。为什么我们有相同大小的
变量的两个名称。


因为它们的大小不一定相同。这是

我遇到的一些方案('位'符号是非正式的,

实际上不是C的一部分):


位(短)== 16,位(int)== 16,位(长)== 32

位(短)== 16,位(int)== 32 ,位(长)== 32

位(短)== 16,位(int)== 32,位(长)== 64


正如您所看到的,int可以与short相同,

或与long相同,或者与两者不同。

各种体系结构的long和int的大小是否会发生变化..




是的。 C语言保证某些最小值和

类型之间的某些关系:


bits(char)> = 8

bits (短)> = 16&& bits(短)> = bits(char)

bits(int)> = 16&& bits(int)> = bits(短)

位(长)> = 32&&位(长)> =位(int)

位(长很长)> = 64&& bit(long long)> = bits(long)


(C99中引入了`long long''类型.C99还允许实现
实现定义他们自己选择的其他类型,

遵守各种规则;我没有试图列举

这些异国情调整数,因为会有不同的在不同的实现上设置

。)


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


Hi,

I am a beginer programmer, i would like to know the exact difference
between long and int. Why do we have two names for the same size of
variable.

Does the size of long and int change on various architectures..

thanks,
carl

解决方案

ri************@gmail.com wrote:

Hi,

I am a beginer programmer, i would like to know the exact difference
between long and int. Why do we have two names for the same size of
variable.
They are not necessarily the same size at all. In fact, it is only
guaranteed that the size of `long` is greater than or equal to that of
an `int`.
Does the size of long and int change on various architectures..



It sometimes does, but that is not required either. It depends more on
the actual C implementation than on the underlying architecture.
There''s nothing stopping an implementation from having 64-bit `long`s
(or `int`s, for that matter), even on a 6-bit machine.

--
BR, Vladimir

I''m shaving!! I''M SHAVING!!


"Vladimir S. Oka" <no****@btopenworld.com> writes:

[...] it is only guaranteed that the size of `long` is greater
than or equal to that of an `int`.



You mean "range", not "size". The range of int is a subrange of
the range of long. There are no such guarantees about the sizes
of int and long.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}




ri************@gmail.com wrote On 02/22/06 18:07,:

Hi,

I am a beginer programmer, i would like to know the exact difference
between long and int. Why do we have two names for the same size of
variable.
Because they''re not necessarily the same size. Here are
some schemes I''ve encountered (the `bits'' notation is informal,
not actually part of C):

bits(short) == 16, bits(int) == 16, bits(long) == 32
bits(short) == 16, bits(int) == 32, bits(long) == 32
bits(short) == 16, bits(int) == 32, bits(long) == 64

As you can see, `int'' could have the same width as `short'',
or the same as `long'', or be different from both.
Does the size of long and int change on various architectures..



Yes. The C language guarantees certain minima and
certain relationships between the types:

bits(char) >= 8
bits(short) >= 16 && bits(short) >= bits(char)
bits(int) >= 16 && bits(int) >= bits(short)
bits(long) >= 32 && bits(long) >= bits(int)
bits(long long) >= 64 && bits(long long) >= bits(long)

(The `long long'' type was introduced in C99. C99 also allows
implementations to define other types of their own choosing,
subject to various rules; I haven''t attempted to enumerate
these "exotic" integers because there''ll be different sets
on different implementations.)

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


这篇关于Long和Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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