detect anonymous union at compile time

Andrej Mitrovic andrej.mitrovich at gmail.com
Thu Mar 28 13:18:44 PDT 2013


On Thursday, 28 March 2013 at 20:02:18 UTC, cal wrote:
> is there any way to detect the fact that fields i and f will 
> have the same offset from S?

void main()
{
     static if (S.init.i.offsetof == S.init.f.offsetof)
         pragma(msg, "Union");
}

> (Creating an instance of S and getting the relative addresses 
> only works if the union is public).

.offsetof will also require access rights to the fields.


More information about the Digitalmars-d-learn mailing list