是否保证char是8位长? [英] Is char guaranteed to be exactly 8-bit long?

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

问题描述

这就是。

推荐答案

ANSI C规范的副本,请参见第3.1.2.5节 - 类型: p>

From a copy of the ANSI C specification, see Section 3.1.2.5 - Types:


声明为char类型的对象是
,足够大到存储
的任何成员基本执行字符集。如果
$ 2.2.1中枚举的所需源
字符集的成员是存储在char对象中的
,则其值为
,保证为正值。如果其他
数量存储在char
对象中,则行为是
实现定义的:值为
被视为signed或
非负整数。 p>

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.

换句话说,char必须至少足够大以包含至少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.

现在添加到部分

$ < b $ b

符合的实现应该
记录在
本节中指定的所有限制,这将在头< limits.h>中指定

< float.h>

整数类型的大小

下面给出的值应为
由常量表达式替换
适用于#if预处理
指令。它们的
实现定义的值应该是
等于或大于等于
(绝对值)的那些值,而
是相同的符号。

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天全站免登陆