字节缓冲区应该是有符号还是无符号字符缓冲区?

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 data
  • unsigned char = byte
  • signed 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.

这篇关于字节缓冲区应该是有符号还是无符号字符缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:字节缓冲区应该是有符号还是无符号字符缓冲区?