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.
这篇关于字节缓冲区应该是有符号还是无符号字符缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字节缓冲区应该是有符号还是无符号字符缓冲区?
基础教程推荐
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 常量变量在标题中不起作用 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
