I was scanning through my config.h and noticed something that startled me a bit. The configure script actually checks what sizeof(char) is, and defines.h relies on this information. This is completely unnecessary. By definition, sizeof(char) is always 1. This is not a matter of opinion; the C standard explicitly states, in ?6.5.3.4 alinea 3, When applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1. On the other hand, unlike other basic integer types, the signedness of char is implementation-defined; see ?6.2.5 alinea 15 and footnote 35. Since int8_t is supposed to be a *signed* 8-bit integer, it must be explicitly defined as such. Code that relies on char being signed will break on IRIX, and probably a number of other implementations. DES -- Dag-Erling Sm?rgrav - des at des.no -------------- next part -------------- A non-text attachment was scrubbed... Name: openssh-sizeof-char.diff Type: text/x-patch Size: 789 bytes Desc: not available URL: <http://lists.mindrot.org/pipermail/openssh-unix-dev/attachments/20110929/fa4c089e/attachment.bin>
On Thu, 29 Sep 2011, Dag-Erling Sm?rgrav wrote:> I was scanning through my config.h and noticed something that startled > me a bit. The configure script actually checks what sizeof(char) is, > and defines.h relies on this information. > > This is completely unnecessary. By definition, sizeof(char) is always > 1. This is not a matter of opinion; the C standard explicitly states, > in ?6.5.3.4 alinea 3, > > When applied to an operand that has type char, unsigned char, or > signed char, (or a qualified version thereof) the result is 1. > > On the other hand, unlike other basic integer types, the signedness of > char is implementation-defined; see ?6.2.5 alinea 15 and footnote 35. > Since int8_t is supposed to be a *signed* 8-bit integer, it must be > explicitly defined as such. Code that relies on char being signed will > break on IRIX, and probably a number of other implementations.applied - thanks