为char保证是完全的8位长? [英] Is char guaranteed to be exactly 8-bit long?

查看:153
本文介绍了为char保证是完全的8位长?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是全部。没有找到任何类似的话题让我忍受的是有的。

That's all. Didn't find any similar topic so bear with me it there is.

推荐答案

ANSI C规范副本,看到的第3.1.2.5 - 类型的:

的对象声明为char类型是
  足够大的存储的任何成员
  基本执行字符集。如果
  所需的源的部件
  字符集列举$ 2.2.1是
  存储在char对象,它的值是
  保证是正的。如果其他
  量被存储在一个字符
  对象,该行为是
  实现定义:值是
  作为符号或者处理
  非负整数。

An object declared as type char is large enough to store any member of the basic execution character set. If a member of the required source character set enumerated in $2.2.1 is stored in a char object, its value is guaranteed to be positive. If other quantities are stored in a char object, the behavior is implementation-defined: the values are treated as either signed or nonnegative integers.

执行字符集的概念被引入的第2.2.1节 - 字符集

The concept of "execution character set" is introduced in Section 2.2.1 - Character sets.

在换句话说,一个字符必须至少大到足以容纳至少95不同的角色从而弥补了基本执行字符集编码。

In other words, a char has to be at least big enough to contain an encoding of at least the 95 different characters which make up the basic execution character set.

现在加入到该节的 2.2.4.2 - 数值范围

一个符合标准的实现应
  文件中规定的所有限制
  这一节,并须指明
  在头文件<&limits.h中GT;
  < float.h时方式>

A conforming implementation shall document all the limits specified in this section, which shall be specified in the headers <limits.h> and <float.h> .

整型尺寸

下面给出的值应
  通过不断的前pressions取代
  适合在#if preprocessing使用
  指令。其
  实现定义值应
  等于或大于在幅度
  (绝对值)的那些中所示,与
  相同的符号。

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.


      为最小位
  • 最大数量
      对象不是一个位域
      (字节)结果CHAR_BIT 8

  • maximum number of bits for smallest object that is not a bit-field (byte)
    CHAR_BIT 8

类型的对象最小值
  符号字符结果SCHAR_MIN -127

minimum value for an object of type signed char
SCHAR_MIN -127

类型的对象最大值
  符号字符结果SCHAR_MAX +127

maximum value for an object of type signed char
SCHAR_MAX +127

类型的对象最大值
  unsigned char型结果UCHAR_MAX 255

maximum value for an object of type unsigned char
UCHAR_MAX 255

...

所以你有它 - 位在字符数必须至少为8

So there you have it - the number of bits in a char must be at least 8.

这篇关于为char保证是完全的8位长?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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