C数据类型'取值范围为"系统"依赖? [英] C data types' value range is "system" dependent?

查看:134
本文介绍了C数据类型'取值范围为"系统"依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始在C编程PROG。语言和想要得到的数据类型,大小,价值主体连胜。

I just started programming in the C prog. language and want to get the data type-size-value subject straight.

我已经看到了不同的数据类型的几个值范围表(这一个这样的)。

I've seen a few value-range tables of different data types (such as this one).

问题是,我已经学会了和读到这里,有哪些影响每个数据类型的大小不同的参数,我的假设是,值范围应有所不同,以及。

The thing is, I've learned and read here that there are different parameters which influence the size of each data type, and my assumption is that the value-range should vary as well.

例如,如果 1字节= 16位那么我觉得符号字符把持不住0-65535

For example, if 1 byte = 16 bit then I'd think signed char could hold 0-65535.

如何准确是那些表?是他们表现出保证的范围内(但在类型既可以实际持有也较小\\较大值)?

How accurate are those tables? Is the range they show guaranteed (but the types could actually hold also smaller\larger values)?

推荐答案

C语言规范没有定义任何确切的范围内为每个数据类型。它只定义了一个的最小的值特定类型应该能够成立。

The C language specification doesn't define any exact range for each data type. It only defines a minimum value that a particular type should be able to hold.

来到你的问题上的的表,它不是范围的准确再presentation由C.定义它可能是提交人运行它在特定平台上实现。但它不能总是(并且不应)取为权威源

Coming to your question on that table, it's NOT the accurate representation of ranges for defined by C. It may be true on a particular platform that the author was running it on. But it can't always be (and shouldn't be) taken as the authoritative source.

如果你想知道你的平台上的确切范围,看(或包含)的< limits.h中> 。或者你可以使用的sizeof 的类型运营商获得的编译器的信息。

If you want to know the exact range on your platform, look at(or include) <limits.h>. Or you can use sizeof operator on the types to get the information from compiler.

如果你想知道的的再使用 CHAR_BIT &LT的确切数字; limits.h中&GT ;

If you are want to know the exact number of bits then use CHAR_BIT defined in <limits.h>.

例如,可以通过使用发现位在一个int数: CHAR_BIT *的sizeof(INT)

For example, the number of bits in an int can be found using: CHAR_BIT * sizeof(int).

在给定类型相同的方式 T ,可以发现位数: CHAR_BIT *的sizeof(T)

In same way for a given type T, number of bits can be found: CHAR_BIT * sizeof(T).

另请阅读首先从C-FAQ 这是相当3个或4个问题有关你的问题。

Also read the first 3 or 4 questions from the C-FAQ which are quite relevant to your question.

这篇关于C数据类型'取值范围为&QUOT;系统&QUOT;依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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