Yes, it will work cross-platform, but that does not necessarily make it a good idea.
In accordance with ISO C (all citations from C11), 6.7.2.1 Structure and union specifiers /15 , before the first element of the structure
filling is not allowed,
In addition, 6.2.7 Compatible type and composite type states that:
Two types have a compatible type if their types are the same
and it is undeniable that types A and A-within-B identical.
This means that the memory, referring to the fields A , will be the same for types A and B , as well as the more reasonable b->ax , which is likely to be used if you have concerns about maintainability in the future.
And, although you usually have to worry about a strict type alias, I don't think this applies here. This is illegal for alias pointers, but the standard has special exceptions.
6.5 Expressions /7 contains some of these footnote exceptions:
The purpose of this list is to indicate the circumstances under which an object may or may not be smoothed.
The listed exceptions:
a type compatible with the effective type of the object ;- some other exceptions that we are not interested in here; and
an aggregate or union type that includes one of the aforementioned types among its members (including, recursively, a member of a subaggregate or contained union) .
This, in combination with the above rules for laying the structure, including the phrase:
A pointer to a structure object, properly transformed, points to its initial member
this example seems to be specifically allowed. Here we must remember that the type of expression ((A*)b) is A* , not B* . This makes the variables compatible for unlimited smoothing.
To my reading of the relevant parts of the standard, I was wrong before (a) but in this case I doubt it.
So, if you have a real need for this, everything will be fine, but I will document any restrictions in the code very close to the structures so as not to bite in the future.
(a) As my wife will tell you, often and without much clue :-)