digitalmars.D.bugs - symbol aliasing in structs
- Hasan Aljudy (23/26) Nov 07 2005 Not sure if this is a bug,
- Regan Heath (5/24) Nov 07 2005 Ahh! So that is what it was doing. I never did figure it out. I would
- Walter Bright (5/18) Nov 07 2005 I'm not sure what is intended here, but b isn't a type, and one can only
- Derek Parnell (40/65) Nov 07 2005 I thought it was obvious what was intended. Namely that "field" is a
- Walter Bright (10/14) Nov 08 2005 Klunky, but this'll work:
- Derek Parnell (8/26) Nov 08 2005 Yuck! Can't you do better? Anyhow, would I have to worry about endian-ne...
- Walter Bright (5/27) Nov 08 2005 bit
- Ivan Senji (6/27) Nov 08 2005 Wouldn't return by reference simplify these cases where property doesn't...
- Walter Bright (6/11) Nov 08 2005 Doing references to bits will require more than just a pointer, it'll ha...
-
Georg Wrede
(18/33)
Nov 09 2005
- Ivan Senji (11/28) Nov 09 2005 So what? Pointers to bits are not regular pointers and trying to
- Walter Bright (5/12) Nov 09 2005 have
- Ivan Senji (7/20) Nov 09 2005 Yes, but you can call a well documented issue a feature :)
- Florian Sonnenberger (17/20) Nov 08 2005 But properties are symbols, right?
- Hasan Aljudy (4/31) Nov 08 2005 Fair enough.
Not sure if this is a bug, this works: #struct Fields but this doesnt: #struct Fields produces error messege: C:\test\d>dmd bits.d bits.d(6): b is used as a type on dmd 0.137 I guess it parsed that as: field is an alias for an array of zero b's. woops, type b is not defined! According to the docs, the compiler should be smart enough to actually figure out whether b is a type or a symbol. Quote from http://www.digitalmars.com/d/declaration.htmlNote: Type aliases can sometimes look indistinguishable from aliasdeclarations:#alias foo.bar abc; // is it a type or a symbol? The distinction is made in the semantic analysis pass.
Nov 07 2005
On Mon, 07 Nov 2005 02:10:35 -0700, Hasan Aljudy <hasan.aljudy gmail.com> wrote:Not sure if this is a bug, this works: #struct Fields but this doesnt: #struct Fields produces error messege: C:\test\d>dmd bits.d bits.d(6): b is used as a type on dmd 0.137 I guess it parsed that as: field is an alias for an array of zero b's. woops, type b is not defined!Ahh! So that is what it was doing. I never did figure it out. I would _love_ for this to work. Regan
Nov 07 2005
"Hasan Aljudy" <hasan.aljudy gmail.com> wrote in message news:dkn5mb$2aq9$1 digitaldaemon.com...Not sure if this is a bug, this works: #struct Fields but this doesnt: #struct FieldsI'm not sure what is intended here, but b isn't a type, and one can only create an alias for a type or a symbol. b[0] is neither, hence an error message. I don't think this is a compiler bug.
Nov 07 2005
On Mon, 7 Nov 2005 22:14:45 -0800, Walter Bright wrote:"Hasan Aljudy" <hasan.aljudy gmail.com> wrote in message news:dkn5mb$2aq9$1 digitaldaemon.com...I thought it was obvious what was intended. Namely that "field" is a shorthand way of referring to "b[0]"; an alias, if you like.Not sure if this is a bug, this works: #struct Fields but this doesnt: #struct FieldsI'm not sure what is intended here,but b isn't a type, and one can only create an alias for a type or a symbol. b[0] is neither, hence an error message. I don't think this is a compiler bug.Fair enough comment. What is the preferred way of referencing individual bits in a platform agnostic manner? If I have a piece of RAM that is 8 bits long, is there some way I can name the bit-fields mapped over that block of RAM? My simplistic attempt has failed big time. struct Fields { bit fldA; bit fldB; bit[4] fldC; bit fldD; bit fldE; } This coding above doesn't seem to map to the 8 bits of my block of RAM. By that I mean that the bit with the lowest address (ie. the address of the 8-bit long block of RAM) is the first bit and is called fldA, the next adjacent bit to the right (higher *bit* address) if fldB, then next four bits is a single field called fldC (values 0 to 15), the next adjacent bit is fldD, and the last bit in the RAM block is fldE. However, I can't seem to set them or get them correctly and the size of the struct is not 1 (one) as I'd expect. void main() { Fields q; q.fldA = 0; q.fldB = 1; q.fldC[] = 1; q.fldD = 0; q.fldE = 1; writefln("%x %d", *(cast(byte*)(&(q))), q.sizeof); } This compiles and prints "0 8" but I expected "7d 1" -- Derek (skype: derek.j.parnell) Melbourne, Australia 8/11/2005 5:36:07 PM
Nov 07 2005
"Derek Parnell" <derek psych.ward> wrote in message news:1tud7p1r6ehw8.sfqxfg7qd4rz$.dlg 40tude.net...What is the preferred way of referencing individual bits in a platform agnostic manner? If I have a piece of RAM that is 8 bits long, is there some way I can name the bit-fields mapped over that block of RAM? My simplistic attempt has failed big time.Klunky, but this'll work: struct Fields { bit foo[8]; bit fldA() { return foo[0]; } bit fldA(bit s) { return foo[0] = s; } ... etc ... }
Nov 08 2005
On Tue, 8 Nov 2005 01:02:07 -0800, Walter Bright wrote:"Derek Parnell" <derek psych.ward> wrote in message news:1tud7p1r6ehw8.sfqxfg7qd4rz$.dlg 40tude.net...Yuck! Can't you do better? Anyhow, would I have to worry about endian-ness with this 'technique'? In other words, does foo[0] always reference the bit with the lowest RAM address? -- Derek Parnell Melbourne, Australia 8/11/2005 11:17:08 PMWhat is the preferred way of referencing individual bits in a platform agnostic manner? If I have a piece of RAM that is 8 bits long, is there some way I can name the bit-fields mapped over that block of RAM? My simplistic attempt has failed big time.Klunky, but this'll work: struct Fields { bit foo[8]; bit fldA() { return foo[0]; } bit fldA(bit s) { return foo[0] = s; } ... etc ... }
Nov 08 2005
"Derek Parnell" <derek psych.ward> wrote in message news:1tz7dpeylfsl0$.1ry62433jeiwu$.dlg 40tude.net...On Tue, 8 Nov 2005 01:02:07 -0800, Walter Bright wrote:bit"Derek Parnell" <derek psych.ward> wrote in message news:1tud7p1r6ehw8.sfqxfg7qd4rz$.dlg 40tude.net...Yuck! Can't you do better? Anyhow, would I have to worry about endian-ness with this 'technique'? In other words, does foo[0] always reference theWhat is the preferred way of referencing individual bits in a platform agnostic manner? If I have a piece of RAM that is 8 bits long, is there some way I can name the bit-fields mapped over that block of RAM? My simplistic attempt has failed big time.Klunky, but this'll work: struct Fields { bit foo[8]; bit fldA() { return foo[0]; } bit fldA(bit s) { return foo[0] = s; } ... etc ... }with the lowest RAM address?It always references the bit with the lowest bit address in the byte, and the lowest byte address in ram.
Nov 08 2005
Walter Bright wrote:"Derek Parnell" <derek psych.ward> wrote in message news:1tud7p1r6ehw8.sfqxfg7qd4rz$.dlg 40tude.net...Wouldn't return by reference simplify these cases where property doesn't need to do any real task except get or set? Something like: inout bit fldA() { return foo[0]; } Is there any chance for this ever to be in D?What is the preferred way of referencing individual bits in a platform agnostic manner? If I have a piece of RAM that is 8 bits long, is there some way I can name the bit-fields mapped over that block of RAM? My simplistic attempt has failed big time.Klunky, but this'll work: struct Fields { bit foo[8]; bit fldA() { return foo[0]; } bit fldA(bit s) { return foo[0] = s; } ... etc ... }
Nov 08 2005
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dkqgot$2jhf$1 digitaldaemon.com...Wouldn't return by reference simplify these cases where property doesn't need to do any real task except get or set? Something like: inout bit fldA() { return foo[0]; } Is there any chance for this ever to be in D?Doing references to bits will require more than just a pointer, it'll have to be a pointer plus a bit number. Then, these won't work like regular pointers. There really isn't a good solution, it's just an issue of where are the seams going to trip you.
Nov 08 2005
Walter Bright wrote:"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dkqgot$2jhf$1 digitaldaemon.com...<flame on> At risk of sounding like a bitching old lady: So even here the bit datatype is not _genuinely_ supported by the language! Either this kind of things should work uniformly with the other integral datatypes (syntactically, that is), or we should consider skipping bit as a separate data type altogether. This would save us from a lot of pretense, and it would let the specification be changed to "bool is implemented internally as the fastest or most convenient integer type, but cast to or from bool is implicitly rewritten as return (value == 0) ? 0 : 1; By this time D is _sexy_ enough to not anymore need such arcane marketing pranks as "bit datatype". Also, even this discussion should serve as an example of the confusion and frustration and misunderstanding and unwarranted hopes, that this pretense fosters. <grrrrr>Wouldn't return by reference simplify these cases where property doesn't need to do any real task except get or set? Something like: inout bit fldA() { return foo[0]; } Is there any chance for this ever to be in D?Doing references to bits will require more than just a pointer, it'll have to be a pointer plus a bit number. Then, these won't work like regular pointers. There really isn't a good solution, it's just an issue of where are the seams going to trip you.
Nov 09 2005
Walter Bright wrote:"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dkqgot$2jhf$1 digitaldaemon.com...Why not?Wouldn't return by reference simplify these cases where property doesn't need to do any real task except get or set? Something like: inout bit fldA() { return foo[0]; } Is there any chance for this ever to be in D?Doing references to bits will require more than just a pointer, it'll have to be a pointer plus a bit number.Then, these won't work like regular pointers.So what? Pointers to bits are not regular pointers and trying to classify them as pointers is wrong. I like the idea of bit type and find that it could be usefull, but as it is now to many things can not be done with them. I wouldn't have anything against bit* being 2*size_t, plus some rules of casting bit* to normal pointers.There really isn't a good solution, it's just an issue of where are the seams going to trip you.I didn't understand this part, but i have to say i wasn't trying to start a bit-war, i was just thinking and trying to say how returning refereces would be a really nice feature. It is probably the *only* thing i miss from C++.
Nov 09 2005
"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dksr7t$t4b$1 digitaldaemon.com...Walter Bright wrote:haveDoing references to bits will require more than just a pointer, it'llI guarantee that, if implemented, there will be issues because it can't be converted back and forth between void*.to be a pointer plus a bit number.Why not?Then, these won't work like regular pointers.So what? Pointers to bits are not regular pointers and trying to classify them as pointers is wrong.
Nov 09 2005
Walter Bright wrote:"Ivan Senji" <ivan.senji_REMOVE_ _THIS__gmail.com> wrote in message news:dksr7t$t4b$1 digitaldaemon.com...Yes, but you can call a well documented issue a feature :) bit[8] bits; //located on adress 0xABCDEFGH bit* bitptr = &bit[1]; // bitptr == {0xABCDEFGH, 1}; void* voidptr = cast(void*)bitptr; //voidptr = {0xABCDEFGH} bitptr* = cast(bit*)voidptr; //bitptr == {0xABCDEFGH, 0}; And it doesn't feel souch a big issue.Walter Bright wrote:I guarantee that, if implemented, there will be issues because it can't be converted back and forth between void*.Then, these won't work like regular pointers.So what? Pointers to bits are not regular pointers and trying to classify them as pointers is wrong.
Nov 09 2005
Walter Bright schrieb:I'm not sure what is intended here, but b isn't a type, and one can only create an alias for a type or a symbol. (...)But properties are symbols, right? So, why does this code not compile: struct foo { int[] bar; alias bar.length size; } ----- foobar.d(19): no property 'length' for type 'int[]' foobar.d(19): bar.length is used as a type ----- This also happens with .sizeof, .min, .max, .alignof, .dup, .init, ... (I already posted this in http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/5301 ) Thanks, Florian
Nov 08 2005
Walter Bright wrote:"Hasan Aljudy" <hasan.aljudy gmail.com> wrote in message news:dkn5mb$2aq9$1 digitaldaemon.com...Fair enough. I wasn't clear on what "symbol" means (I think I'm still not clear on it). I thought that "symbol" just means "variable".Not sure if this is a bug, this works: #struct Fields but this doesnt: #struct FieldsI'm not sure what is intended here, but b isn't a type, and one can only create an alias for a type or a symbol. b[0] is neither, hence an error message. I don't think this is a compiler bug.
Nov 08 2005