Should a buffer of bytes be signed or unsigned char buffer?(字节缓冲区应该是有符号还是无符号字符缓冲区?)
问题描述
字节缓冲区应该是有符号字符还是无符号字符,或者只是一个字符缓冲区?C 和 C++ 有什么区别?
Should a buffer of bytes be signed char or unsigned char or simply a char buffer? Any differences between C and C++?
谢谢.
推荐答案
是否应该对字节缓冲区进行签名char 或 unsigned char 或只是一个 char缓冲?C和C之间的任何差异C++?
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(或 UTF-8,但有符号阻碍)textual data无符号字符
= 字节signed char
= 很少使用
char
= ASCII (or UTF-8, but the signedness gets in the way there) textual dataunsigned char
= bytesigned char
= rarely used
并且有代码依赖这种区别.就在一两个星期前,我遇到了一个错误,即 JPEG 数据被损坏,因为它被传递给我们的 Base64 编码函数的 char*
版本......其中有用"替换了字符串"中所有无效的 UTF-8.只需更改为 BYTE
aka unsigned char
即可修复它.
And 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 to BYTE
aka unsigned char
was all it took to fix it.
这篇关于字节缓冲区应该是有符号还是无符号字符缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字节缓冲区应该是有符号还是无符号字符缓冲区?
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- C++ 协变模板 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 近似搜索的工作原理 2021-01-01