D - why is byte signed and char unsigned ?
- imr1984 (3/3) Mar 14 2004 surely D has got it the wrong way round?
- C. Sauls (10/14) Mar 14 2004 This is simple, as a quick read-through of
- Vathix (5/9) Mar 14 2004 I agree. C# has byte for unsigned and sbyte for signed. I think D has
- Matthew (7/10) Mar 14 2004 With byte, perhaps.
- Andy Friesen (3/6) Mar 14 2004 That's unusual. Why?
- Matthew (10/15) Mar 14 2004 able
- Walter (3/4) Apr 02 2004 void[] and void* fill the role of opaque memory.
- Derek Parnell (9/16) Mar 14 2004 Could it be that a byte is a set of eight consecutive bits without
- Mark T (28/31) Mar 14 2004 I guess Walter followed Java where they are 8 bit signed integers becaus...
- =?ISO-8859-1?Q?Sigbj=F8rn_Lund_Olsen?= (6/19) Mar 14 2004 While I agree in the sense that I generally think of '0 - 255' when
- Charles Hixson (11/35) Mar 15 2004 I tend to think of a byte as a packed array of bits, which can
- Manfred Nowak (10/10) Mar 15 2004 Mark T wrote:
- larry cowan (7/16) Mar 15 2004 A byte is generally the smallest individually addressible multibit unit ...
- Manfred Nowak (8/12) Mar 15 2004 [...]
- Serge K (3/8) Mar 22 2004 Don't look that far - many popular DSP have the smallest addressable uni...
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.
Mar 14 2004
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
Mar 14 2004
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.ubyte and byte to be consistent with short/int/long. -- Christopher E. Miller
Mar 14 2004
"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 thathaveyet to be given a specific meaning - so a byte should be unsigned.
Mar 14 2004
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
Mar 14 2004
"Andy Friesen" <andy ikagames.com> wrote in message news:c31u6v$sjn$1 digitaldaemon.com...Matthew wrote:ableIMO, byte should not be an integral type, in so far as it should not betheto take place in integer operations. However, I know I'm whistling inBecause 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.wind on this one, as usual.That's unusual. Why?
Mar 14 2004
"Matthew" <matthew stlsoft.org> wrote in message news:c31uik$tfc$1 digitaldaemon.com...Because I view a byte as an opaque unit of memory.void[] and void* fill the role of opaque memory.
Apr 02 2004
On Sun, 14 Mar 2004 07:39:11 -0800 (15/Mar/04 02:39:11 AM) , Andy Friesen <andy ikagames.com> wrote:Matthew wrote: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. -- DerekIMO, 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?
Mar 14 2004
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; ============================= 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.
Mar 14 2004
Mark T wrote:In article <c31i17$9qv$1 digitaldaemon.com>, imr1984 says...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 Olsensurely 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;
Mar 14 2004
Sigbjørn Lund Olsen wrote:Mark T wrote:I tend to think of a byte as a packed array of bits, which can frequently be interpreted as a 8-bit integer, signed or unsigned. But the integer interpretations are definitely a secondary overlay on the underlying meaning. And were I to assign a language specific secondary meaning, it would be that array of bits. And I don't know which end of the byte should correspond to bit[0]...but they should be sequential. Probably the 0 bit would be the left-hand bit, and the one's position, when interpreted as an int, would be the right bit. OTOH, it's been a long time since I used a system where I used this relation much. Or could depend on it when going cross-platform.In article <c31i17$9qv$1 digitaldaemon.com>, imr1984 says...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 Olsensurely 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;
Mar 15 2004
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!
Mar 15 2004
In article <c348lp$1njk$1 digitaldaemon.com>, Manfred Nowak says...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, therebyA byte is generally the smallest individually addressible multibit unit pf storage. It would not be spread in multiple places. Although you would go a ways to find a computer with other than 8-bit bytes, there are still 4-bit memories around. In the past I know of 7, 8, 12 and 16 bit ones with or without one or more indirectly accessible additional parity bits.introducing the need of explicitely defining an order on them.Have you heard of big-endian and little-endian?
Mar 15 2004
On Mon, 15 Mar 2004 20:08:32 +0000, larry cowan wrote: [...][...]| A set of BitsA byte is generally the smallest individually addressible multibit unit pf storage.This is quite a better definition.Have you heard of big-endian and little-endian?These are only philosophical derivates of an already existing strict ordering imposed on the bits. A "set of Bits" has no ordering. So that defintion should be considered plain wrong :-) So long!
Mar 15 2004
A byte is generally the smallest individually addressible multibit unit pf storage. It would not be spread in multiple places. Although you would go a ways to find a computer with other than 8-bit bytes, there are still 4-bit memories around. In the past I know of 7, 8, 12 and 16 bit ones with or without one or more indirectly accessible additional parity bits.Don't look that far - many popular DSP have the smallest addressable unit >8bit. There are many 16 and 32 bit devices around. Some DSP have more odd word sizes (like 24 bit).
Mar 22 2004