¿Se garantiza que int16_t está firmado?

Es el int16_t type declared in <stdint.h> garantiza to be signed, or is it just Supuesto 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.

Could someone confirm this either way? I'd really appreciate specific references to the spec, if at all possible.

preguntado el 09 de enero de 11 a las 07:01

2 Respuestas

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 y una uint16_t,la 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 existe. If you have CHAR_BIT==9, for example, there cannot be a int16_t tipo.

Respondido el 09 de enero de 11 a las 11:01

The topic is addressed more explicitly in 7.18.1.1 p1: "The typedef name intN_t designates a signed integer type with width N , no padding bits, and a two’s complement representation." - David German

"If you have CHAR_BIT==9, for example, there might be no int16_t type." should read "If you have CHAR_BIT==9, for example, there cannot be an int16_t type." - R .. GitHub DEJA DE AYUDAR A ICE

@R.. Yes, looks like you're right. I was thinking there might be an 18-bit type with 2 padding bits, but padding bits are specifically disallowed in intN_t types. - Philip Potter

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

Respondido el 09 de enero de 11 a las 10:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.