更新时间:2023-11-08 08:07:16
应的字节的缓冲器签署
char或unsigned char或只是一个char
缓冲? C和之间的差异
C ++?
块引用>在语言如何处理这微小的差别。 A 大在约定如何处理它的区别。
字符
= ASCII(或UTF-8,但带符号获取的方式出现)的文本数据unsigned char型
=字节符号字符
=很少使用
和有code,它的依赖于这样的区别的。就在两个星期前,我遇到过的JPEG数据越来越损坏,因为它被传递到
的char *
版本我们的Base64 EN code函数&MDASH的一个bug;其中有益全部换成了无效的UTF-8,在串。更改为字节
又名unsigned char型
是所有花来解决它。Should a buffer of bytes be signed char or unsigned char or simply a char buffer? Any differences between C and C++?
Thanks.
Should a buffer of bytes be signed char or unsigned char or simply a char buffer? Any differences between C and C++?
A minor difference in how the language treats it. A huge difference in how convention treats it.
char
= ASCII (or UTF-8, but the signedness gets in the way there) textual dataunsigned char
= bytesigned char
= rarely usedAnd there is code that relies on such a distinction. Just a week or two ago I encountered a bug where JPEG data was getting corrupted because it was being passed to the
char*
version of our Base64 encode function — which "helpfully" replaced all the invalid UTF-8 in the "string". Changing toBYTE
akaunsigned char
was all it took to fix it.