签名字符有什么意义? [英] What is the point of signed char?

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

问题描述




签名字符的重点是什么?我看到它的一个字符代表一个

字符(不是一个整数,如果你想要

一个8位数字,或者一个新的,使用一个int类型,例如short int类型,uint8我认为)。


我不知道任何使用底片的字符集,例如65是''A''

和-65是''a''?!?


我肯定我错过了什么,任何想法?


另外,我是否正确地说当前的标准声明

char是签名还是未签名是依赖于实现的?


尼克

解决方案



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



什么是签名的char点?正如我所看到的那样,char代表一个
字符(不是整数,使用int类型,例如short int,如果你想要一个8位数字,或者其中一种新类型,我认为是uint8。) br />
我不知道任何使用底片的字符集,例如65是'A''
而-65是''a''?!?

我确定我错过了什么,有什么想法吗?

另外,我是否正确地说当前的标准声明,无论是签名还是未签名的字符是否依赖于实现?

Nick




如果你有一个整数变量,其值可以介于

-127到127之间,那么你可以使用signed char来节省空间。




ju **** ******@yahoo.co.in 写道:

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



签名字符的重点是什么?正如我所看到的那样,char代表一个
字符(不是整数,使用int类型,例如short int,如果你想要一个8位数字,或者其中一种新类型,我认为是uint8。) br />
我不知道任何使用底片的字符集,例如65是'A''
而-65是''a''?!?

我确定我错过了什么,有什么想法吗?

另外,我是否正确地说当前的标准声明,无论是签名还是未签名的字符是否依赖于实现?

Nick


<如果你有一些整数变量可以在
-127到127之间,那么你可以使用signed char来节省空间。




如果我存储一个整数然后乖乖,那么使用

整数类型会更好吗?如果我担心空间,那么我可以使用int8_t(来自

C99 stdint.h)。据我了解,除非我使用stdint.h类型我

不保证超过大小,甚至不能用于char。


我不是对的建议''char''应该用于字符

和'int''应该用于整数?如果我是对的那么当我没有使用的字符集使用

负数时,签名字符的

点是什么?


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

ju**********@yahoo.co。在写道:

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

签名字符的重点是什么?正如我所看到的那样,char代表一个
字符(不是整数,使用int类型,例如short int,如果你想要一个8位数字,或者其中一种新类型,我认为是uint8。) / blockquote>
如果你有一个整数变量,其值可以在-127到127之间,那么你可以使用signed char来节省空间。
Buf如果我要存储一个整数那么使用
整数类型会更好吗?




所有三种字符类型_are_整数类型。

如果我担心空间然后我可以使用int8_t(来自
C99 stdint.h)。




如果你有C99,是的。如果您的实现具有8位类型,是的。如果

你只想要保证最小的整数类型,你总是可以使用

char。


是的,它会''如果有两套独立的

类型,char和byte,那就更好了。但这就是它的成长方式。


Richard


Hi,

What''s the point of a signed char? As I see it a char represents a
character (not an integer, use an int type e.g. short int if you want
an 8 bit number, or one of the new types, uint8 I think).

I don''t know of any character sets that use negatives, e.g. 65 is ''A''
and -65 is ''a''?!?

I''m sure I''m missing something, any ideas?

Also, am I right in saying that the current standards state that
whether a char is signed or unsigned is implementation dependent?

Nick

解决方案



ng****@gmail.com wrote:

Hi,

What''s the point of a signed char? As I see it a char represents a
character (not an integer, use an int type e.g. short int if you want
an 8 bit number, or one of the new types, uint8 I think).

I don''t know of any character sets that use negatives, e.g. 65 is ''A''
and -65 is ''a''?!?

I''m sure I''m missing something, any ideas?

Also, am I right in saying that the current standards state that
whether a char is signed or unsigned is implementation dependent?

Nick



If you have some integer variable that could have values in between
-127 to 127, then you can use signed char to save space.




ju**********@yahoo.co.in wrote:

ng****@gmail.com wrote:

Hi,

What''s the point of a signed char? As I see it a char represents a
character (not an integer, use an int type e.g. short int if you want
an 8 bit number, or one of the new types, uint8 I think).

I don''t know of any character sets that use negatives, e.g. 65 is ''A''
and -65 is ''a''?!?

I''m sure I''m missing something, any ideas?

Also, am I right in saying that the current standards state that
whether a char is signed or unsigned is implementation dependent?

Nick



If you have some integer variable that could have values in between
-127 to 127, then you can use signed char to save space.



Buf if I''m storing an integer then surly it would be better to use an
integer type? If I''m worried about space then I could use int8_t (from
C99 stdint.h). As I understand it unless I use the stdint.h types I
have no guarantee over size, not even for a char.

Am I not right in suggesting that ''char'' should be used for characters
and ''int'' should be used for integers? If I am right then what is the
point of a signed char when no character set that I''m aware of uses
negative numbers?


ng****@gmail.com wrote:

ju**********@yahoo.co.in wrote:

ng****@gmail.com wrote:

What''s the point of a signed char? As I see it a char represents a
character (not an integer, use an int type e.g. short int if you want
an 8 bit number, or one of the new types, uint8 I think).

If you have some integer variable that could have values in between
-127 to 127, then you can use signed char to save space.
Buf if I''m storing an integer then surly it would be better to use an
integer type?



All three char types _are_ integer types.
If I''m worried about space then I could use int8_t (from
C99 stdint.h).



If you have C99, yes. If your implementation has an 8 bit type, yes. If
you just want the guaranteed smallest integer type, you can always use
char.

Yes, it would''ve been better if there had been two separate sets of
types, char and byte. But this is how it has grown to be.

Richard


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

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