Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
April 06, 2014 Typo in Types page | ||||
---|---|---|---|---|
| ||||
In the page http://dlang.org/type.html I believe there is a typo stating that bool is 1 byte instead of 1 bit. |
April 06, 2014 Re: Typo in Types page | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gustavo | On Sunday, 6 April 2014 at 09:30:47 UTC, Gustavo wrote: > In the page http://dlang.org/type.html I believe there is a typo stating that bool is 1 byte instead of 1 bit. While a boolean is by definition a single bit, it is represented by programming languages as a byte for various reasons (including performance, data layout, and interfacing). You can verify that this is the case: http://dpaste.dzfl.pl/8129625be797 As far as I know, this is true for most, if not all, native programming languages. To actually store a value as a single bit, you will have to use bit manipulation. |
April 06, 2014 Re: Typo in Types page | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gustavo | On Sunday, 6 April 2014 at 09:30:47 UTC, Gustavo wrote: > In the page http://dlang.org/type.html I believe there is a typo stating that bool is 1 byte instead of 1 bit. I don't think it's a typo. Memory is typically byte-addressable and thus data types are either a byte or larger. Having a data type smaller than a byte means reading or writing to that variable will have to involve bit-twiddling operations which can make operations more expensive. There are bitfields[1] and BitArrays[2] if you really need control of a data type on the bit level. [1]: http://dlang.org/phobos/std_bitmanip.html#.bitfields [2]: http://dlang.org/library/std/bitmanip/BitArray.html |
April 07, 2014 Re: Typo in Types page | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gustavo | On 4/6/14, Gustavo <gbuschle@hotmail.com> wrote:
> In the page http://dlang.org/type.html I believe there is a typo stating that bool is 1 byte instead of 1 bit.
static assert(byte.sizeof == 1); // 1 *byte*
|
April 07, 2014 Re: Typo in Types page | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | Am Mon, 7 Apr 2014 08:48:02 +0200 schrieb Andrej Mitrovic <andrej.mitrovich@gmail.com>: > On 4/6/14, Gustavo <gbuschle@hotmail.com> wrote: > > In the page http://dlang.org/type.html I believe there is a typo stating that bool is 1 byte instead of 1 bit. > > static assert(byte.sizeof == 1); // 1 *byte* static assert(bool.sizeof == 1); // 1 *byte* There I fixed it ;) -- Marco |
April 07, 2014 Re: Typo in Types page | ||||
---|---|---|---|---|
| ||||
Posted in reply to Marco Leise | On 4/7/14, Marco Leise <Marco.Leise@gmx.de> wrote:
> static assert(bool.sizeof == 1); // 1 *byte*
>
> There I fixed it ;)
LOL!
|
Copyright © 1999-2021 by the D Language Foundation