我一直认为在C中,int
代表signed int
;但我听说这种行为是特定于平台的,在某些平台中,int
默认为 unsigned
。是真的吗?标准是怎么说的,它是否随着时间的推移而演变?
最佳答案
你说的很对。根据 C11
(最新的 c 标准),第 §6.7.2 章
int
,signed
, orsigned int
被归类为相同的类型(确切地说是类型说明符)。因此,int
与 signed int
相同。
此外,重申相同的内容,来自第 §6.2.5/P4 章
There are five standard signed integer types, designated as
signed char
,short int
,int
,long int
, andlong long int
. (These and other types may be designated in several additional ways, as described in 6.7.2.) [....]
因此,对于任何符合标准的环境,int
代表 signed int
,反之亦然。
关于c - `int` 总是签名的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44624857/