如果字节的缓冲区进行签名或无符号的字符缓冲区? [英] Should a buffer of bytes be signed or unsigned char buffer?

查看:153
本文介绍了如果字节的缓冲区进行签名或无符号的字符缓冲区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果字节的缓冲区签署char或unsigned char或只是一个字符缓冲区?
C和C ++之间的任何差别?

感谢。


解决方案

  

应的字节的缓冲器签署
  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 data
  • unsigned char = byte
  • signed char = rarely used

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.

这篇关于如果字节的缓冲区进行签名或无符号的字符缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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