Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: OpenSSH: Dev

sizeof(char)

 

 

OpenSSH dev RSS feed   Index | Next | Previous | View Threaded


des at des

Sep 28, 2011, 5:32 PM

Post #1 of 8 (701 views)
Permalink
sizeof(char)

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
Attachments: openssh-sizeof-char.diff (0.77 KB)


djm at mindrot

Sep 28, 2011, 6:12 PM

Post #2 of 8 (678 views)
Permalink
Re: sizeof(char) [In reply to]

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
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


openssh at roumenpetrov

Sep 29, 2011, 12:43 PM

Post #3 of 8 (672 views)
Permalink
Re: sizeof(char) [In reply to]

Damien Miller wrote:
> 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
>
I don't know what you apply but patch as is just say good bay on old
systems where char is with sizeof integer. I don't think that check for
size of char has to be removed .
Only part "typedef signed char int8_t;" make sense .

Regards,
Roumen


--
Get X.509 certificates support in OpenSSH:
http://roumenpetrov.info/openssh/

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


openssh at roumenpetrov

Sep 29, 2011, 12:54 PM

Post #4 of 8 (678 views)
Permalink
Re: sizeof(char) [In reply to]

Roumen Petrov wrote:
> Damien Miller wrote:
>> 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
> I don't know what you apply but patch as is just say good bay on old
> systems where char is with sizeof integer. I don't think that check
> for size of char has to be removed .
> Only part "typedef signed char int8_t;" make sense .
>
> Regards,
> Roumen
May be *AC_TYPE_INT8_T* macro could help - cf
http://www.gnu.org/s/hello/manual/autoconf/Particular-Types.html

Roumen

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


des at des

Sep 29, 2011, 1:37 PM

Post #5 of 8 (672 views)
Permalink
Re: sizeof(char) [In reply to]

Roumen Petrov <openssh [at] roumenpetrov> writes:
> I don't know what you apply but patch as is just say good bay on old
> systems where char is with sizeof integer.

I suggest you read what I wrote, and the passage I quoted from the C
standard.

To summarize: sizeof(char) == 1. Always. No exceptions.

DES
--
Dag-Erling Smørgrav - des [at] des
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


openssh at roumenpetrov

Sep 29, 2011, 2:04 PM

Post #6 of 8 (673 views)
Permalink
Re: sizeof(char) [In reply to]

Dag-Erling Smrgrav wrote:
> Roumen Petrov<openssh [at] roumenpetrov> writes:
>
>> I don't know what you apply but patch as is just say good bay on old
>> systems where char is with sizeof integer.
>>
> I suggest you read what I wrote, and the passage I quoted from the C
> standard.
>
:)

> To summarize: sizeof(char) == 1. Always. No exceptions.
>
Sure. I cannot run my time machine and to return 20 years ago .

sizeof(char) == 1 does not mean that size if 8 bit . Did you read documentation for*AC_TYPE_INT8_T* ?


> DES
>
Roumen
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


des at des

Sep 29, 2011, 3:25 PM

Post #7 of 8 (675 views)
Permalink
Re: sizeof(char) [In reply to]

Roumen Petrov <openssh [at] roumenpetrov> writes:
> Dag-Erling Smørgrav <des [at] des> writes:
> > To summarize: sizeof(char) == 1. Always. No exceptions.
> Sure. I cannot run my time machine and to return 20 years ago .

Even if you could, sizeof(char) would still be 1. The C standard
requires it.

> sizeof(char) == 1 does not mean that size if 8 bit . Did you read
> documentation for*AC_TYPE_INT8_T* ?

The code in defines.h assumes 8 bits per byte. That's not my doing, nor
does my patch change that fact, and it is completely orthogonal to the
issue I brought up, which was that sizeof(char) is always 1.

DES
--
Dag-Erling Smørgrav - des [at] des
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev


william at 25thandClement

Sep 30, 2011, 2:52 PM

Post #8 of 8 (671 views)
Permalink
Re: sizeof(char) [In reply to]

On Thu, Sep 29, 2011 at 10:37:59PM +0200, Dag-Erling Sm??rgrav wrote:
> Roumen Petrov <openssh [at] roumenpetrov> writes:
> > I don't know what you apply but patch as is just say good bay on old
> > systems where char is with sizeof integer.
>
> I suggest you read what I wrote, and the passage I quoted from the C
> standard.
>
> To summarize: sizeof(char) == 1. Always. No exceptions.
>

Just to clarify this a bit for those confused, if sizeof (char) == sizeof
(int) then sizeof (int) == 1, and CHAR_BIT >= 16.

Not only is this required by the spec, but it's fundamental to the machine
model upon which C and similar languages are based. The relationships are
never going to change.

_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev [at] mindrot
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev

OpenSSH dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.