Re: detect anonymous union at compile time

2013-03-28 Thread Andrej Mitrovic
On 3/28/13, cal wrote: > Just realized that format.d is able to figure it out, since it > prints #{overlap...} for unions. I can use that code, which works > regardless of protection. Thanks Ah, I didn't even know .tupleof would contain .offsetof. void main() { static if (S.tupleof[0].offset

Re: detect anonymous union at compile time

2013-03-28 Thread cal
On Thursday, 28 March 2013 at 20:18:45 UTC, Andrej Mitrovic wrote: On Thursday, 28 March 2013 at 20:02:18 UTC, cal wrote: .offsetof will also require access rights to the fields. Just realized that format.d is able to figure it out, since it prints #{overlap...} for unions. I can use that code

Re: detect anonymous union at compile time

2013-03-28 Thread cal
On Thursday, 28 March 2013 at 20:18:45 UTC, Andrej Mitrovic wrote: .offsetof will also require access rights to the fields. Yeh this is the problem. I can map data layout of complex aggregates, even if the members are private, but unions mess that up. Restricting to public fields is an option

Re: detect anonymous union at compile time

2013-03-28 Thread Andrej Mitrovic
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 relat

detect anonymous union at compile time

2013-03-28 Thread cal
Given: struct S { union { int i; float f; } } is there any way to detect the fact that fields i and f will have the same offset from S? (Creating an instance of S and getting the relative addresses only works if the union is public).