What's wrong with this:
TTest = record
A: Integer;
B: record
case Boolean of
True: (A: Integer);
False: (B: Integer);
end;
C: Integer;
end;
It already works, but I don't know if this is C compatible (in terms of alignment)
No, that isn't the same and doesn't work in the way of the nameless union.
In your example:
"A" at the first entry will always be there by itself and no other item will live there.
In my example:
"A" and "B" share the same memory location at the start.
Your use of a record solves many problems except for the fact that it does not solve the anonymous issues, you have now forced a new tag requirement.
You will also note that I extended the first branch of "A" to add additional items in the record. These items are now not in the realm being selective, they are basically following after either "A" or "B".
Maybe I should of make the example different.
Type
TAnonymousExample = Record
Case boolean of
True :(A:Integer);
False:(B:Integer;
C:Integer;
S:String[10];
W:WORD;)
End;
Looking at that code, C,S and W will always exist following A or B. where A and B occupy the same space.
You will also note, there is no additional TAGS being added.
This of course makes for a messy looking record but it does work just like C anonymous unions. The downside is that you need to complete the record in the tree order of the CASE...