<分区>
我认为标题是不言自明的,但为了更好的格式。
sizeof(unsigned char)
也保证为 1 吗?
我不认为这个问题是重复的,因为:
- C 与 C++ 不同(标签摘录:
...它最初被设计为 C 的扩展,并保持相似的语法,但现在是一种完全不同的语言...
)。 char
可以是有符号的或无符号的。没有理由假设sizeof(unsigned char)
==sizeof(char)
除非您得到标准的保证,因此才有问题。- 即使您将 C 与 C++ 混淆,答案也不会重叠。
<分区>
我认为标题是不言自明的,但为了更好的格式。
sizeof(unsigned char)
也保证为 1 吗?
我不认为这个问题是重复的,因为:
...它最初被设计为 C 的扩展,并保持相似的语法,但现在是一种完全不同的语言...
)。 char
可以是有符号的或无符号的。没有理由假设 sizeof(unsigned char)
== sizeof(char)
除非您得到标准的保证,因此才有问题。最佳答案
是的。
[expr.sizeof]/1:
sizeof(char)
,sizeof(signed char)
andsizeof(unsigned char)
are1
.
此外,[basic.fundamental]/1:
A
char
, asigned char
, and anunsigned char
occupy the same amount of storage and have the same alignment requirements
关于c++ - sizeof(unsigned char) 也保证为 1 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27464867/