digitalmars.D.bugs - Anonymous unions
- Derek Parnell (35/35) May 31 2005 I think the code below is supposed to compile...
- Hasan Aljudy (15/55) May 31 2005 I think anonymous unions have no names (hence anonymous)
- Derek Parnell (7/32) May 31 2005 Thanks. Yes it does.
- Chris Sauls (35/36) May 31 2005 Actually no, no it doesn't.. I just tested with this:
- Stewart Gordon (8/10) Jun 01 2005 An anonymous union doesn't create a scope. And so it's illegal for
- Andrew Fedoniouk (19/54) May 31 2005 Derek, anonymous means 'no type name'
-
Stewart Gordon
(16/31)
Jun 01 2005
- Andrew Fedoniouk (3/31) Jun 01 2005 Thanks Stewart. It was my Cism.
I think the code below is supposed to compile... struct S { union Anon { int Int; real Atom; } } void main() { S test; } But I get this message ... test.d(13): need 'this' to access member Int I need to change it to this to get it to compile ... struct S { union Anon { int Int; real Atom; } Anon A; } void main() { S test; test.A.Int = 2; } -- Derek Melbourne, Australia 1/06/2005 1:02:30 PM
May 31 2005
Derek Parnell wrote:I think the code below is supposed to compile... struct S { union Anon { int Int; real Atom; } }I think anonymous unions have no names (hence anonymous) So strictly speaking, the union above is probably not anonymous. This should probably compile: struct S { union { int Int; real Atom; } }void main() { S test; } But I get this message ... test.d(13): need 'this' to access member IntAnon is the type name, not an instance. I think that's why it needs a "this" (i.e. an instance)I need to change it to this to get it to compile ... struct S { union Anon { int Int; real Atom; } Anon A; } void main() { S test; test.A.Int = 2; }This (I think) is c++'s way of doing it .. it's definitly not anonymous.
May 31 2005
On Tue, 31 May 2005 21:12:14 -0600, Hasan Aljudy wrote:Derek Parnell wrote:Thanks. Yes it does. But I guess it means only one anonymous union per struct though ;-) -- Derek Melbourne, Australia 1/06/2005 1:26:13 PMI think the code below is supposed to compile... struct S { union Anon { int Int; real Atom; } }I think anonymous unions have no names (hence anonymous) So strictly speaking, the union above is probably not anonymous. This should probably compile: struct S { union { int Int; real Atom; } }
May 31 2005
Derek Parnell wrote:But I guess it means only one anonymous union per struct though ;-)Actually no, no it doesn't.. I just tested with this: Although granted, naming might be interesting when having multiple anonymous unions. -- Chris Sauls
May 31 2005
Chris Sauls wrote: <snip>Although granted, naming might be interesting when having multiple anonymous unions.An anonymous union doesn't create a scope. And so it's illegal for names to collide between them. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 01 2005
Derek, anonymous means 'no type name' and not 'no variable name' variable name - alias of some memory location must always exist if you want to store something there. So you should write something like this: struct S { union { int Int; real Atom; } var; } And then S s; s.var.Int = 28; Andrew. "Derek Parnell" <derek psych.ward> wrote in message news:14ds0mvtn12la$.1nc9wu744dnbg.dlg 40tude.net...I think the code below is supposed to compile... struct S { union Anon { int Int; real Atom; } } void main() { S test; } But I get this message ... test.d(13): need 'this' to access member Int I need to change it to this to get it to compile ... struct S { union Anon { int Int; real Atom; } Anon A; } void main() { S test; test.A.Int = 2; } -- Derek Melbourne, Australia 1/06/2005 1:02:30 PM
May 31 2005
Andrew Fedoniouk wrote:Derek, anonymous means 'no type name' and not 'no variable name' variable name - alias of some memory location must always exist if you want to store something there. So you should write something like this: struct S { union { int Int; real Atom; } var; }<snip top of upside-down reply> Illegal in D. Should be struct S { union Var { int Int; real Atom; } Var var; } Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jun 01 2005
"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message news:d7klmr$2090$1 digitaldaemon.com...Andrew Fedoniouk wrote:Thanks Stewart. It was my Cism.Derek, anonymous means 'no type name' and not 'no variable name' variable name - alias of some memory location must always exist if you want to store something there. So you should write something like this: struct S { union { int Int; real Atom; } var; }<snip top of upside-down reply> Illegal in D. Should be struct S { union Var { int Int; real Atom; } Var var; } Stewart.
Jun 01 2005