问题描述
c的语义) / code>以 unsigned char )定义。
In C, unsigned char is the only type guaranteed to have no trapping values, and which guarantees copying will result in an exact bitwise image. (C++ extends this guarantee to char as well.) For this reason, it is traditionally used for "raw memory" (e.g. the semantics of memcpy are defined in terms of unsigned char).
此外,一般用于位操作(& , | ,> code>等)将被使用。 unsigned char 是最小的无符号整数类型,可以在操作使用按位运算的小值数组时使用。有时,它也被使用,因为在溢出的情况下需要模数行为,虽然这对于较大的类型(例如当计算哈希值时)更频繁。这两个原因一般适用于无符号类型; unsigned char 通常只会在需要减少内存使用时使用。
In addition, unsigned integral types in general are used when bitwise operations (&, |, >> etc.) are going to be used. unsigned char is the smallest unsigned integral type, and may be used when manipulating arrays of small values on which bitwise operations are used. Occasionally, it's also used because one needs the modulo behavior in case of overflow, although this is more frequent with larger types (e.g. when calculating a hash value). Both of these reasons apply to unsigned types in general; unsigned char will normally only be used for them when there is a need to reduce memory use.
这篇关于何时使用unsigned char指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!