Anonymous structure
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 18 08:59:11 PDT 2016
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 testUDA;
> struct T{
> @testUDA
> immutable struct{
> int x;
> int y;
> int z;
> }
> }
>
> 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
>
> enum testUDA;
> struct T{
> @testUDA
> immutable{
> int x;
> int y;
> int z;
> }
> }
>
> So it still seems to be useless other than in the case of unions...
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.
-Steve
More information about the Digitalmars-d-learn
mailing list