Originally Posted by
grumpy
Depends what you mean by safe.
Your code, as presented, only sets the values of struct members x,y, and z and only ever retrieves values of them. There is no usage of the member p. As such, the behaviour is well specified.
The behaviour would be undefined if one member of the union is set and another member is used to retrieve (e.g. setting x,y,z but retrieving p[0],p[1], and p[2]).
That said, a fair few library functions would rely on the layout aligning. But "what implementations do" is not the same as "what standards require".