无符号的字符 [英] unsigned char

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

问题描述

c标准是否规定所有c99实现char为标准

等于unsigned char ??? - 或者我必须考虑到这一点

编写我的程序???。

Does the c standard state that for all c99 implementation char as standard
is equal unsigned char ??? - or do i have to take this into account when
writing my program ???.

推荐答案

Lars Tackmann写道:
Lars Tackmann wrote:
c标准是否规定所有c99实现char为标准
等于unsigned char?
Does the c standard state that for all c99 implementation char as standard
is equal unsigned char ?




完全没有。它等同于signed char或unsigned char。

选择取决于实现。


它不是_equal_,虽然。这是一个独特的类型,所以

char * foo;

unsigned char * bar = foo;

即使char是错误也是错误的相当于unsigned char。


-

Hallvard



Not at all. It''s equivalent to either signed char or unsigned char.
The choice is up to the implementation.

It''s not _equal_ to either, though. It''s a distinct type, so
char *foo;
unsigned char *bar = foo;
is an error even if char is equivalent to unsigned char.

--
Hallvard


Lars Tackmann< ro ** **@diku.dk>写道:
Lars Tackmann <ro****@diku.dk> wrote:
c标准是否表示​​对于所有c99实现char作为标准
是否等于unsigned char ??? - 或者我必须在编写程序时考虑到这一点???。
Does the c standard state that for all c99 implementation char as standard
is equal unsigned char ??? - or do i have to take this into account when
writing my program ???.




实现必须从{signed | unsigned}中选择一个char

forplain char:


ISO / IEC 9899:1999 6.2.5#15

char,signed char和unsigned char这三种类型是

统称为字符类型。实现

应定义char具有相同的范围,表示,

以及行为为signed char或unsigned char。





ISO / IEC 9899:1999 6.3.1.1#3

整数提升保留包括符号在内的值。正如前面讨论过的那样,无论是平原还是平淡。 char被视为

签名是实现定义的。

HTH

问候

-

Irrwahn Grausewitz(ir*******@freenet.de)

欢迎来到clc: http://www.angelfire.com/ms3/bchambl...me_to_clc.html

clc faq-列表: http://www.eskimo.com/~ scs / C-faq / top.html

acllc-c ++ faq: http://www.contrib.andrew.cmu.edu/~a...acllc-c++.html



The implementation has to pick one from {signed|unsigned} char
for "plain" char:

ISO/IEC 9899:1999 6.2.5#15
The three types char, signed char, and unsigned char are
collectively called the character types. The implementation
shall define char to have the same range, representation,
and behavior as either signed char or unsigned char.

and

ISO/IEC 9899:1999 6.3.1.1#3
The integer promotions preserve value including sign. As
discussed earlier, whether a "plain" char is treated as
signed is implementation-defined.
HTH
Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.angelfire.com/ms3/bchambl...me_to_clc.html
clc faq-list : http://www.eskimo.com/~scs/C-faq/top.html
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...acllc-c++.html


Hallvard B Furuseth写道:
Hallvard B Furuseth wrote:
Lars Tackmann写道:

Lars Tackmann wrote:

是否c标准状态,对于所有c99实现char作为标准
是否等于unsigned char?
Does the c standard state that for all c99 implementation char as standard
is equal unsigned char ?



不在al湖它等同于签名字符或无符号字符。
选择取决于实现。

但它不是_equal_。它是一种独特的类型,所以
char * foo;
unsigned char * bar = foo;
即使char等同于unsigned char也是错误。


Not at all. It''s equivalent to either signed char or unsigned char.
The choice is up to the implementation.

It''s not _equal_ to either, though. It''s a distinct type, so
char *foo;
unsigned char *bar = foo;
is an error even if char is equivalent to unsigned char.




注意指向unsigned char的指针可以指向对象中的任何字节。

因此,如果foo已经正确初始化,上面的内容将是合法的。


但即便

int * p;

int * p2 = p;


是一个错误,因为它使用未初始化变量的值。


-

Thomas。



Note that pointers to unsigned char can point to any byte in an object.
So if foo had been properly initialised the above would have been legal.

But even
int *p;
int *p2 = p;

is an error since it uses the value of an uninitialised variable.

--
Thomas.

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

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