Thread overview | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 14, 2004 why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
surely D has got it the wrong way round? Usually when people talk about 'bytes' they refer to areas of memory that have yet to be given a specific meaning - so a byte should be unsigned. |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | imr1984 wrote: > surely D has got it the wrong way round? > > Usually when people talk about 'bytes' they refer to areas of memory that have > yet to be given a specific meaning - so a byte should be unsigned. This is simple, as a quick read-through of 'http://www.digitalmars.com/d/type.html' would show you. D's 8-bit integral type is byte (or ubyte for unsigned). So when we say byte, we mean a 1-byte integer. That's it. Char is unsigned because its supposed to be used for text, and is Unicode complient. If you want bytes without a specific meaning, then use ubyte or the void[] special case. I've done this a few times myself, with no problem. -C. Sauls -Invironz |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | imr1984 wrote: > surely D has got it the wrong way round? > > Usually when people talk about 'bytes' they refer to areas of memory that have > yet to be given a specific meaning - so a byte should be unsigned. > I agree. C# has byte for unsigned and sbyte for signed. I think D has ubyte and byte to be consistent with short/int/long. -- Christopher E. Miller |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | "imr1984" <imr1984_member@pathlink.com> wrote in message news:c31i17$9qv$1@digitaldaemon.com... > surely D has got it the wrong way round? With byte, perhaps. IMO, byte should not be an integral type, in so far as it should not be able to take place in integer operations. However, I know I'm whistling in the wind on this one, as usual. > Usually when people talk about 'bytes' they refer to areas of memory that have > yet to be given a specific meaning - so a byte should be unsigned. |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to imr1984 | In article <c31i17$9qv$1@digitaldaemon.com>, imr1984 says... > >surely D has got it the wrong way round? > >Usually when people talk about 'bytes' they refer to areas of memory that have yet to be given a specific meaning - so a byte should be unsigned. > > I guess Walter followed Java where they are 8 bit signed integers because ============================== the Windows SDK uses typedef unsigned char BYTE; ============================= C# Programmer's Reference byte The byte keyword denotes an integral type that stores values as indicated in the following table. Type Range Size byte 0 to 255 Unsigned 8-bit integer ====================================================== Glossary of Internet Terms: Byte A set of Bits that represent a single character. Usually there are 8 Bits in a Byte, sometimes more, depending on how the measurement is being made. ========================================================== I don't think I have ever needed a negative number that must fit into 8 bits but I guess there are cases. I tend to agree that a byte is a chunk of memory that is 8 bits wide. tangent: I did suggest a while back that D follow the C99 stdint.h lead and use int8_t, uint8_t, int16_t, etc (D could drop the _t ) for exact width types and let int and long match the typical C complier for the architecture (byte wouldn't be used). Such as DEC/Compaq/HP C/C++ for Alpha, Intel C/C++ for Itanium, dmc or VC for Win32, gcc for Linux-x86, etc. |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | Matthew wrote:
> IMO, byte should not be an integral type, in so far as it should not be able
> to take place in integer operations. However, I know I'm whistling in the
> wind on this one, as usual.
That's unusual. Why?
-- andy
|
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | "Andy Friesen" <andy@ikagames.com> wrote in message news:c31u6v$sjn$1@digitaldaemon.com... > Matthew wrote: > > IMO, byte should not be an integral type, in so far as it should not be able > > to take place in integer operations. However, I know I'm whistling in the > > wind on this one, as usual. > > That's unusual. Why? Because I view a byte as an opaque unit of memory. I'd prefer separate 1-byte sized integers. This is how I have it in the STLSoft libraries, with ss_sint8_t, ss_uint8_t and ss_byte_t. Same goes for bool. In D I tend to do this typedef int boolean; which makes it a distinct type and hides implicit conversions. |
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark T | Mark T wrote:
> In article <c31i17$9qv$1@digitaldaemon.com>, imr1984 says...
>
>>surely D has got it the wrong way round?
>>
>>Usually when people talk about 'bytes' they refer to areas of memory that have
>>yet to be given a specific meaning - so a byte should be unsigned.
>>
>>
>
> I guess Walter followed Java where they are 8 bit signed integers because
> ==============================
> the Windows SDK uses
> typedef unsigned char BYTE;
While I agree in the sense that I generally think of '0 - 255' when thinking of a 'byte', it *is* consistent with the other integral types. And the Windows SDK is rarely an example to follow.
Cheers,
Sigbjørn Lund Olsen
|
March 14, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andy Friesen | On Sun, 14 Mar 2004 07:39:11 -0800 (15/Mar/04 02:39:11 AM) , Andy Friesen <andy@ikagames.com> wrote: > Matthew wrote: >> IMO, byte should not be an integral type, in so far as it should not be able >> to take place in integer operations. However, I know I'm whistling in the >> wind on this one, as usual. > > That's unusual. Why? > Could it be that a byte is a set of eight consecutive bits without structure, and an eight-bit integer is only one of many possible structures used to interpret the meaning in a specific 8-bit sequence. Thus a byte is just a group of bits, and an integer is a specific way of applying meaning to those bits. -- Derek |
March 15, 2004 Re: why is byte signed and char unsigned ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark T | Mark T wrote: [...] | A set of Bits [...] | Usually there are 8 Bits in a Byte, sometimes more [...] Never thought of that! Then a byte can not only take more than eight bits, but also can be distributed over several places of storage, thereby introducing the need of explicitely defining an order on them. So long! |
Copyright © 1999-2021 by the D Language Foundation