是否总是对int进行签名? [英] Is `int` always signed?
问题描述
我一直认为在C语言中, int
代表 signed int
;但是我听说这种行为是特定于平台的,在某些平台上,默认情况下 int
是 unsigned
.是真的吗该标准说了什么,它随着时间的推移而发展了吗?
I always thought that in C, int
stands for signed int
; but I have heard that this behavior is platform specific and in some platforms, int
is unsigned
by default. Is it true? What says the standard, and has it evolved over time?
推荐答案
您说得很对.按照 C11
(最新的 c 标准),第6.7.2章
You are quite right. As per C11
(the latest c standard), chapter §6.7.2
int
,signed
或signed int
被归为相同的 type (确切地说是类型说明符).因此, int
与 signed int
相同.
is categorized as same type (type specifiers, to be exact). So, int
is the same as signed int
.
在第6.2.5/P4章中再次重申相同的内容
Also, re-iterating the same, from chapter §6.2.5/P4
有五种标准有符号整数类型,分别指定为
signed char
,shortint
,int
,long int
和long long int
.(这些和其他类型可能是以其他几种方式指定,如6.7.2所述.)[....]
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
,反之亦然.
So, for any conforming environment, int
stands for signed int
and vice versa.
这篇关于是否总是对int进行签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!