C99 draft standard states (Annex J):
J.2 Undefined behavior
The behavior is undefined in the following circumstances:
[...]
An object is assigned to an inexactly overlapping object or to an exactly overlapping
object with incompatible type (6.5.16.1).
then, for what concerns compatible types:
6.2.7 Compatible type and composite type
Two types have compatible type if their types are the same. Additional rules for
determining whether two types are compatible are described in 6.7.2 for type specifiers,
in 6.7.3 for type qualifiers, and in 6.7.5 for declarators. Moreover, two structure,
union, or enumerated types declared in separate translation units are compatible if their
tags and members satisfy the following requirements: If one is declared with a tag, the
other shall be declared with the same tag. If both are complete types, then the following
additional requirements apply: there shall be a one-to-one correspondence between their
members such that each pair of corresponding members are declared with compatible
types, and such that if one member of a corresponding pair is declared with a name, the
other member is declared with the same name. For two structures, corresponding
members shall be declared in the same order. For two structures or unions, corresponding
bit-fields shall have the same widths. For two enumerations, corresponding members
shall have the same values.
making the two structs the same size is not sufficient to make them compatible types, so the behavior is undefined.
Edit: for sake of completeness I add the excerpt cited by @PascalCuoq in a comment to another answer in this thread, which is also relevant:
6.5 Expressions
[...]
7
An object shall have its stored value accessed only by an lvalue expression that has one of the following types:
- a type compatible with the effective type of the object,
- a qualified version of a type compatible with the effective type of the object,
- a type that is the signed or unsigned type corresponding to the effective type of the
object,
- a type that is the signed or unsigned type corresponding to a qualified version of the
effective type of the object,
- 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), or
- a character type.