Nasty supprise when using c 'anonymous struct and union' in D with 'static struct'

Arjan arjan at ask.me.to
Tue Dec 29 12:38:11 UTC 2020


see https://en.cppreference.com/w/c/language/struct

It seems the 'static' must NOT be used here to get the equivalent 
behavior of c, when left in the assertions will fail.

Is this expected?

```
unittest
{

struct W
{
align(1):
     long k;
     long l;
}

struct V
{
align(1):
     union // anonymous union
     {
         /*static*/ struct // anonymous structure
         {
             long i;
             long j;
         }
         W w;
    }
    int m;
}

V v1;

v1.i = 2;
assert( 2 == v1.w.k );
v1.w.l = 5;
assert( 5 == v1.j );
}
```






More information about the Digitalmars-d-learn mailing list