开发者

Is int16_t guaranteed to be signed?

Is the int16_t type declared in <stdint.h> guaranteed to be signed, or is it just supposed to be signed? I would assume that it would have to be signed, but surprisingly I can't seem to find any hard evidence (i.e. references to the spec) that explicitly mention this anywhere.

Cou开发者_Go百科ld someone confirm this either way? I'd really appreciate specific references to the spec, if at all possible.


n1256 7.18.1p1 says:

When typedef names differing only in the absence or presence of the initial u are defined, they shall denote corresponding signed and unsigned types as described in 6.2.5; an implementation providing one of these corresponding types shall also provide the other.

Since there is an int16_t and a uint16_t, the int16_t is therefore signed.

Or indeed 7.18.1.1p1:

The typedef name intN_t designates a signed integer type with width N , no padding bits, and a two’s complement representation. Thus, int8_t denotes a signed integer type with a width of exactly 8 bits.

which is more explicit about it.

EDIT: although strictly speaking, int16_t is not guaranteed to be signed in the sense that it's not guaranteed to exist. If you have CHAR_BIT==9, for example, there cannot be a int16_t type.


Yes, int16_t is guaranteed to be signed two's complement by the ISO spec.

  • http://linux.die.net/man/3/int16_t
  • http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf page 256
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜