digitalmars.D - [bug?] dynamic bit array append
- novice2 (33/33) Jan 05 2005 Hello.
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (10/14) Jan 06 2005 Compiling with GDC 0.9 gives an error:
- novice2 (3/6) Jan 06 2005 yes. i already used this "bypass".
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (17/21) Jan 06 2005 It's the D way. Sometimes the default type
-
Stewart Gordon
(13/24)
Jan 12 2005
- Chris Sauls (13/22) Jan 06 2005 As an aside, if you are actually doing this in your project (wanting to ...
- Lionello Lunesu (10/16) Jan 07 2005 Hi.
- Simon Buchan (10/31) Jan 07 2005 Since bit arrays seem to only be supported on byte boundries, if at all,...
- novice2 (6/12) Jan 12 2005 I wanted avoid ugly and bad readable by humans "calc mask, shift, or"
Hello. I met problem - i can't append one bit to bit array. Is it bug or i missed something? My environment: Windows XP, DMD 0.110 Small test program: /*********** "version = v_set" works properly. it print: bits:111111111111 "version = v_append" not works. it print: bits:100000001000 Sorry, if i missed something *********/ //version = v_set; version = v_append; void main() { bit[] bits; version(v_set) { bits.length = 12; for( int i=0; i<12; i++) bits[i] = 1; } version(v_append) { for( int i=0; i<12; i++) bits ~= 1; } printf( "bits:"); foreach( bit b; bits) printf("%d",b); printf("\n"); }
Jan 05 2005
novice2 wrote:I met problem - i can't append one bit to bit array. Is it bug or i missed something?Bug or "missing feature", you be the judge...My environment: Windows XP, DMD 0.110Compiling with GDC 0.9 gives an error: "sorry; can't append to array of bit"Small test program:[snip] If you change the "bit" to "byte" instead, your small test program works just fine ? It's (yet another) thing missing from bit arrays, along with e.g. taking pointers to bits in arrays... --anders
Jan 06 2005
Bug or "missing feature", you be the judge...it is a pity :(If you change the "bit" to "byte" instead, your small test program works just fine ?yes. i already used this "bypass". thanks, anders.
Jan 06 2005
novice2 wrote:It's the D way. Sometimes the default type is not enough, so you need to use the two wide variants that are also being provided... For instance, a "char" will hold any ASCII character but if you need to support Unicode you need a "wchar". And then, when you also need to be aware of surrogates* you need "dchar" Similarly, when you need a "bit" type that you can adress in arrays you need to use the "wbit" (byte) type. And for speed, you might want "dbit" (int) that for instance Object's opEquals() method uses. And yes, it is somewhat confusing that there are three string types and three boolean types in D. But it is also rather powerful, a trade-off there. --andersIf you change the "bit" to "byte" instead, your small test program works just fine ?yes. i already used this "bypass".
Jan 06 2005
Anders F Björklund wrote:novice2 wrote:On DMD, the fact it's doing it wrong shows that it's a bone fide bug.I met problem - i can't append one bit to bit array. Is it bug or i missed something?Bug or "missing feature", you be the judge...<snip> On GDC, OTOH, it's a missing feature. Of course, you could call it a bug that the feature is missing in GDC. But that's still better than having a completely broken implementation. But I thought last time I knew it was working to append one bit, just not to concatenate whole bit arrays. But I'll check again. I have a testcase at home.... Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.My environment: Windows XP, DMD 0.110Compiling with GDC 0.9 gives an error: "sorry; can't append to array of bit"
Jan 12 2005
In article <criq09$17hn$1 digitaldaemon.com>, novice2 says...version(v_set) { bits.length = 12; for( int i=0; i<12; i++) bits[i] = 1; } version(v_append) { for( int i=0; i<12; i++) bits ~= 1; }As an aside, if you are actually doing this in your project (wanting to set all elements to 1) you might prefer the following anyhow: -- Chris Sauls -- invironz
Jan 06 2005
Hi. "novice2" <novice2_member pathlink.com> wrote in message news:criq09$17hn$1 digitaldaemon.com..."version = v_set" works properly. it print: bits:111111111111 "version = v_append" not works. it print: bits:100000001000It makes sense actually: for the dynamic arrays, D only tracks the size of the array in bytes, it doesn't keep an index of the last bit. Appending a bit apparently appends a byte, always. I guess appending to a bit array should be simply forbidden (like in gdc, if I'm correct). (But maybe it's useful to be able to append multiple of 8 bits at a time) L.
Jan 07 2005
On Fri, 7 Jan 2005 10:56:56 +0200, Lionello Lunesu <lionello.lunesu crystalinter.remove.com> wrote:Hi. "novice2" <novice2_member pathlink.com> wrote in message news:criq09$17hn$1 digitaldaemon.com...Since bit arrays seem to only be supported on byte boundries, if at all, why bother? I don't know about you, but how much better is"version = v_set" works properly. it print: bits:111111111111 "version = v_append" not works. it print: bits:100000001000It makes sense actually: for the dynamic arrays, D only tracks the size of the array in bytes, it doesn't keep an index of the last bit. Appending a bit apparently appends a byte, always. I guess appending to a bit array should be simply forbidden (like in gdc, if I'm correct). (But maybe it's useful to be able to append multiple of 8 bits at a time) L.bit[8*3] foo = \b10100011_10011011; // Or whatever the syntax isthanubyte[3] bar = \xb39c; // I assume my bin->hex isn't off today?since neither are that readable by humans. (yes, flags, but AFAIK those are just as easy to do with bit-masks, if more verbose in some cases) -- "Yes, the american troops have advanced further. This will only make it easier for us to defeat them" - Iraqi Information Minister Muhammed Saeed al-Sahaf
Jan 07 2005
Since bit arrays seem to only be supported on byte boundries, if at all, why bother?I wanted avoid ugly and bad readable by humans "calc mask, shift, or" constructions. As i work with bits, so i wanted to work with bits, not bytes. And i found in D language datatype "bit" and bit[] - good! By it has restrictions - bad :(I don't know about you, but how much better isI know hex. But it is not good-looking. Algorithm needs calculate bits one by one and append it to bits string.bit[8*3] foo = \b10100011_10011011; // Or whatever the syntax isthanubyte[3] bar = \xb39c; // I assume my bin->hex isn't off today?
Jan 12 2005