Re: Bitfields

2019-05-22 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 22 May 2019 at 08:54:45 UTC, Russel Winder wrote: On Tue, 2019-05-21 at 19:14 +, Era Scarecrow via Digitalmars-d-learn wrote: […] I worked on/with bitfields in the past, the limit sizes is more or less for natural int types that D supports. Rust bitfield crate and it's

Re: Bitfields

2019-05-22 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2019-05-21 at 19:14 +, Era Scarecrow via Digitalmars-d-learn wrote: > […] > I worked on/with bitfields in the past, the limit sizes is more > or less for natural int types that D supports. Rust bitfield crate and it's macros are the same, the underlying type for a bitfield must be

Re: Bitfields

2019-05-22 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2019-05-21 at 18:22 +, Boris-Barboris via Digitalmars-d-learn wrote: […] > > Never used it myself, but BitArray with careful handling of > endianess might fit your task. > > https://dlang.org/phobos/std_bitmanip.html#.BitArray.this.2 > https://dlang.org/phobos/std_bitmanip.html#.peek

Re: Bitfields

2019-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: As far as I can see std.bitmanip only caters for 8, 16, 32, and 64 bit long bitfields. I worked on/with bitfields in the past, the limit sizes is more or less for natural int types that D supports. However this limitation is kin

Re: Bitfields

2019-05-21 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: Hi, Has anyone used D to work with arbitrary length bitfields with multiple occurences of a sub-bitfield. I am working with DVB Sections and EIT packets are defined as bitfields with loops in them and the header is 112 bits. The lo

Re: bitfields - Default values?

2012-06-12 Thread Era Scarecrow
On Tuesday, 12 June 2012 at 15:51:31 UTC, Era Scarecrow wrote: On Tuesday, 12 June 2012 at 13:05:26 UTC, bearophile wrote: Are you able to support a syntax like: struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); } That does look cleaner and better

Re: bitfields - Default values?

2012-06-12 Thread Era Scarecrow
On Tuesday, 12 June 2012 at 13:05:26 UTC, bearophile wrote: Era Scarecrow: struct defs { mixin(bitfields_D!( bitfields!( //borrowed from std.bitmanip bool, "b", 1, uint, "i", 3, short, "s", 4), "i=2", "s=5")); } Are you able to support a syntax like: struct defs {

Re: bitfields - Default values?

2012-06-12 Thread Dmitry Olshansky
On 12.06.2012 17:05, bearophile wrote: Era Scarecrow: Are you able to support a syntax like: struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=2", 3, short, "s=5", 4)); } Or iff bitfields is a mixin template: struct defs { mixin bitfields!( bool, "b", 1, uint, "i=2",

Re: bitfields - Default values?

2012-06-12 Thread bearophile
Era Scarecrow: struct defs { mixin(bitfields_D!( bitfields!( //borrowed from std.bitmanip bool, "b", 1, uint, "i", 3, short, "s", 4), "i=2", "s=5")); } Are you able to support a syntax like: struct defs { mixin(bitfields!( bool, "b", 1, uint, "i=

Re: bitfields - Default values?

2012-06-12 Thread Era Scarecrow
On Tuesday, 5 June 2012 at 00:17:08 UTC, bearophile wrote: Era Scarecrow: The documentation for bitfields doesn't go into detail if you can put any default values into it. Can you? I think you can't. See: http://d.puremagic.com/issues/show_bug.cgi?id=4425 Bye, bearophile K, I think I have

Re: bitfields - Default values?

2012-06-04 Thread bearophile
Era Scarecrow: The documentation for bitfields doesn't go into detail if you can put any default values into it. Can you? I think you can't. See: http://d.puremagic.com/issues/show_bug.cgi?id=4425 Bye, bearophile

Re: bitfields

2009-06-30 Thread downs
novice2 wrote: > downs Wrote: >> Here's a way to do it. >> >> Enjoy! :) >> >> Usage example: >> >> struct Test { >> ... skipped... > > Thank you, downs, for your job! > > but, heh, i can't use something, that i can't understand :( > i hate template and mixin (imho it lead to full unreadable code

Re: bitfields

2009-06-28 Thread novice2
downs Wrote: > > Here's a way to do it. > > Enjoy! :) > > Usage example: > > struct Test { > ... skipped... Thank you, downs, for your job! but, heh, i can't use something, that i can't understand :( i hate template and mixin (imho it lead to full unreadable code). so with my dumbness, i nee

Re: bitfields

2009-06-27 Thread downs
novice2 wrote: > does anyone know: is D2 std.bitmanip compatible with C bitfields? > can i use it, if i need translate .h file with something like this: > > typedef struct { > unsigned int can_compress : 1; > unsigned int can_uncompress : 1; > unsigned int can_get_info : 1; > unsig

Re: bitfields

2009-06-18 Thread Jarrett Billingsley
On Thu, Jun 18, 2009 at 10:28 AM, novice2 wrote: > Jarrett Billingsley Wrote: > >> It's entirely possible to have two different C compilers >> output different code for the same bitfield definitions.  For that > > Dut how is include files for interfacing is published officialy? For example > Sun J

Re: bitfields

2009-06-18 Thread novice2
Jarrett Billingsley Wrote: > It's entirely possible to have two different C compilers > output different code for the same bitfield definitions. For that Dut how is include files for interfacing is published officialy? For example Sun Java SDK .h files have bitfields to interfacing with java VM

Re: bitfields

2009-06-18 Thread bearophile
Jarrett Billingsley: > Practically speaking, sure. Most C compilers will take the path of > least resistance and just pack all the bitfields together as tightly > as they can starting with the LSB, and that is - AFAIK - what > std.bitmanip's bitfield support does. But there are no guarantees. Th

Re: bitfields

2009-06-18 Thread Jarrett Billingsley
On Thu, Jun 18, 2009 at 9:16 AM, novice2 wrote: > does anyone know: is D2 std.bitmanip compatible with C bitfields? > can i use it, if i need translate .h file with something like this: > > typedef struct { >    unsigned int can_compress : 1; >    unsigned int can_uncompress : 1; >    unsigned int