Re: Anonymous structure

2016-04-19 Thread ZombineDev via Digitalmars-d-learn
On Tuesday, 19 April 2016 at 20:19:37 UTC, ZombineDev wrote: On Tuesday, 19 April 2016 at 20:18:07 UTC, ZombineDev wrote: On Tuesday, 19 April 2016 at 17:16:00 UTC, Tofu Ninja wrote: On Tuesday, 19 April 2016 at 16:16:39 UTC, ZombineDev wrote: On Monday, 18 April 2016 at 23:00:42 UTC, captaind

Re: Anonymous structure

2016-04-19 Thread ZombineDev via Digitalmars-d-learn
On Tuesday, 19 April 2016 at 20:18:07 UTC, ZombineDev wrote: On Tuesday, 19 April 2016 at 17:16:00 UTC, Tofu Ninja wrote: On Tuesday, 19 April 2016 at 16:16:39 UTC, ZombineDev wrote: On Monday, 18 April 2016 at 23:00:42 UTC, captaindet wrote: On 2016-04-18 14:12, Tofu Ninja wrote: Also is ther

Re: Anonymous structure

2016-04-19 Thread ZombineDev via Digitalmars-d-learn
On Tuesday, 19 April 2016 at 17:16:00 UTC, Tofu Ninja wrote: On Tuesday, 19 April 2016 at 16:16:39 UTC, ZombineDev wrote: On Monday, 18 April 2016 at 23:00:42 UTC, captaindet wrote: On 2016-04-18 14:12, Tofu Ninja wrote: Also is there a way to have a named substructure, not a nested structure

Re: Anonymous structure

2016-04-19 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 19 April 2016 at 16:16:39 UTC, ZombineDev wrote: On Monday, 18 April 2016 at 23:00:42 UTC, captaindet wrote: On 2016-04-18 14:12, Tofu Ninja wrote: Also is there a way to have a named substructure, not a nested structure but something to just add an additional name, maybe something

Re: Anonymous structure

2016-04-19 Thread ZombineDev via Digitalmars-d-learn
On Monday, 18 April 2016 at 23:00:42 UTC, captaindet wrote: On 2016-04-18 14:12, Tofu Ninja wrote: Also is there a way to have a named substructure, not a nested structure but something to just add an additional name, maybe something like struct a{ struct{ int x; int y;

Re: Anonymous structure

2016-04-19 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 18 April 2016 at 23:00:42 UTC, captaindet wrote: not sure what you mean by "named substructure, not a nested structure" but this works: struct Outer{ struct Inner{ int x; int y; int z; } Inner inner; int

Re: Anonymous structure

2016-04-19 Thread Adrian Matoga via Digitalmars-d-learn
On Monday, 18 April 2016 at 15:59:11 UTC, Steven Schveighoffer wrote: I wonder if it makes a difference for layout. So for example: struct T { struct { int x; ubyte y; } ubyte z; } If there is padding inserted between y and z. There isn't. T.init.z.offsetof - T.init.y.

Re: Anonymous structure

2016-04-18 Thread captaindet via Digitalmars-d-learn
On 2016-04-18 14:12, Tofu Ninja wrote: Also is there a way to have a named substructure, not a nested structure but something to just add an additional name, maybe something like struct a{ struct{ int x; int y; int z; } b; } not sure what you mean by "named

Re: Anonymous structure

2016-04-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/17/16 11:57 PM, Tofu Ninja wrote: On Monday, 18 April 2016 at 03:33:53 UTC, Adam D. Ruppe wrote: The struct inside union is the main pure-language use case I know of though. Actually curiously I found another potential use, applying attributes/UDAs to multiple members at once. enum testU

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 03:57:26 UTC, Tofu Ninja wrote: x,y,and z seem to all be immutable and all have the UDA testUDA. But even odder, it seems that "struct" in there is doing absolutely nothing. The same thing can be done with Yeah, any attribute can be grouped with braces or colons in

Re: Anonymous structure

2016-04-17 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 18 April 2016 at 03:33:53 UTC, Adam D. Ruppe wrote: The struct inside union is the main pure-language use case I know of though. Actually curiously I found another potential use, applying attributes/UDAs to multiple members at once. enum testUDA; struct T{ @testUDA

Re: Anonymous structure

2016-04-17 Thread Tofu Ninja via Digitalmars-d-learn
On Monday, 18 April 2016 at 03:33:53 UTC, Adam D. Ruppe wrote: The struct inside union is the main pure-language use case I know of though. I understand the reason for allowing it in a union, I just don't see the reason it was extended to all aggregates as it seems to do nothing.

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 02:42:15 UTC, Nicholas Wilson wrote: IIRC D doesn't allow anonymous structures. They are allowed only if they are inside another aggregate.

Re: Anonymous structure

2016-04-17 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 18 April 2016 at 02:12:24 UTC, Tofu Ninja wrote: Just out of curiosity, what is the point of the following? struct a{ struct{ int x; int y; int z; } } The grouping matters when it is nested inside a union. Here's a re

Re: Anonymous structure

2016-04-17 Thread Tofu Ninja via Digitalmars-d-learn
far as I can tell, the anonymous structure does nothing. How is it different from struct a{ int x; int y; int z; } IIRC D doesn't allow anonymous structures. It does, it compiles... Accessing x,y,z on the first one with the anonymous struct is the sa

Re: Anonymous structure

2016-04-17 Thread Nicholas Wilson via Digitalmars-d-learn
On Monday, 18 April 2016 at 02:12:24 UTC, Tofu Ninja wrote: Just out of curiosity, what is the point of the following? struct a{ struct{ int x; int y; int z; } } As far as I can tell, the anonymous structure does nothing. How is

Anonymous structure

2016-04-17 Thread Tofu Ninja via Digitalmars-d-learn
Just out of curiosity, what is the point of the following? struct a{ struct{ int x; int y; int z; } } As far as I can tell, the anonymous structure does nothing. How is it different from struct a{ int x; int y