www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Typo in Types page

reply "Gustavo" <gbuschle hotmail.com> writes:
In the page http://dlang.org/type.html I believe there is a typo 
stating that bool is 1 byte instead of 1 bit.
Apr 06 2014
next sibling parent "Philpax" <phillip philliplarkson.com> writes:
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.
Apr 06 2014
prev sibling next sibling parent "Kelet" <kelethunter gmail.com> writes:
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
Apr 06 2014
prev sibling next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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*
Apr 06 2014
prev sibling next sibling parent Marco Leise <Marco.Leise gmx.de> writes:
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
Apr 07 2014
prev sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/7/14, Marco Leise <Marco.Leise gmx.de> wrote:
 static assert(bool.sizeof == 1);  // 1 *byte*

 There I fixed it ;)

LOL!
Apr 07 2014