digitalmars.D - array of bit enum
- =?ISO-8859-1?Q?Val=E9ry?= (28/28) Apr 05 2005 The result of the following code suggests that arrays of bit enum are
- Sean Kelly (3/6) Apr 05 2005 Bits are only packed in arrays. They otherwise occupy 1 byte.
- =?ISO-8859-1?Q?Val=E9ry?= (2/10) Apr 05 2005 Sure. I wonder if enums of type bit are packed in arrays too.
-
Stewart Gordon
(21/24)
Apr 06 2005
- Thomas Kuehne (11/31) Apr 06 2005 -----BEGIN PGP SIGNED MESSAGE-----
The result of the following code suggests that arrays of bit enum are not packed the way array of plain bit are. Do we have to avoid enums when we want 1-bit bits ? Valéry enum Color : bit { BLACK, WHITE } const int size = 50; int main() { List l = new List(null); for (int i = 0; i < 10; i++) l = new List(l); return 0; } class List { this(List l) { b.length = size; c.length = size; tail = l; if (tail) // prints "16 64" on my system printf("%d %d\n", &tail.b[0] - &b[0], &tail.c[0] - &c[0]); } List tail = null; bit[] b; Color[] c; }
Apr 05 2005
In article <d2us47$2si6$1 digitaldaemon.com>, =?ISO-8859-1?Q?Val=E9ry?= says...The result of the following code suggests that arrays of bit enum are not packed the way array of plain bit are. Do we have to avoid enums when we want 1-bit bits ?Bits are only packed in arrays. They otherwise occupy 1 byte. Sean
Apr 05 2005
Sean Kelly a écrit :In article <d2us47$2si6$1 digitaldaemon.com>, =?ISO-8859-1?Q?Val=E9ry?= says...Sure. I wonder if enums of type bit are packed in arrays too.The result of the following code suggests that arrays of bit enum are not packed the way array of plain bit are. Do we have to avoid enums when we want 1-bit bits ?Bits are only packed in arrays. They otherwise occupy 1 byte.
Apr 05 2005
Valéry wrote:The result of the following code suggests that arrays of bit enum are not packed the way array of plain bit are. Do we have to avoid enums when we want 1-bit bits ?<snip> That strikes me as a bug. Here's a simpler testcase: ---------- import std.stdio; enum Colour : bit { BLACK, WHITE } bit[16] b; Colour[16] c; void main() { byte* b0 = cast(byte*) &b[0]; byte* b8 = cast(byte*) &b[8]; byte* c0 = cast(byte*) &c[0]; byte* c8 = cast(byte*) &c[8]; writefln("%d %d", &b8 - &b0, &c8 - &c0); } ---------- Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Apr 06 2005
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Stewart Gordon schrieb am Wed, 06 Apr 2005 17:40:28 +0100:Valéry wrote:prints: 1 1 (Linux dmd-0.119) Is this OS dependent? Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCVCat3w+/yD4P9tIRArwDAKCmAz7TzFUZTgG3RuC0jRyg3xhx9QCgixT8 bcZJORyIAlwzg3GwjEL6gjs= =1MMU -----END PGP SIGNATURE-----The result of the following code suggests that arrays of bit enum are not packed the way array of plain bit are. Do we have to avoid enums when we want 1-bit bits ?<snip> That strikes me as a bug. Here's a simpler testcase: ---------- import std.stdio; enum Colour : bit { BLACK, WHITE } bit[16] b; Colour[16] c; void main() { byte* b0 = cast(byte*) &b[0]; byte* b8 = cast(byte*) &b[8]; byte* c0 = cast(byte*) &c[0]; byte* c8 = cast(byte*) &c[8]; writefln("%d %d", &b8 - &b0, &c8 - &c0); } ----------
Apr 06 2005