sizeof(unsigned char)也保证为1吗?

doc*_*doc 0 c++ sizeof

我认为标题是不言自明的,但更好的格式.

难道sizeof(unsigned char)还保证是1?


我不相信这个问题是重复的,因为:

  • C与C++(标签摘录:)不同...It was originally designed as an extension to C, and keeps a similar syntax, but is now a completely different language....
  • char可以是签名或未签名.除非你得到标准的保证,否则没有理由假设sizeof(unsigned char)== sizeof(char)因此问题.
  • 即使您将C与C++混淆,答案也不会重叠.

小智 8

参考:http://en.cppreference.com/w/cpp/language/sizeof

sizeof(char),sizeof(signed char)和sizeof(unsigned char)始终返回1.


Ant*_*vin 6

是.

[expr.sizeof]/1:

sizeof(char),sizeof(signed char)sizeof(unsigned char)1.

另外,[basic.fundamental]/1:

A char,a signed char和a unsigned char占用相同的存储量并具有相同的对齐要求