It is safe, as far as I know.
But it's far better, if possible, to do:
typedef struct {
Struct1 struct1;
short another_short;
} Struct2;
Then you've even told the compiler that Struct2
starts with an instance of Struct1
, and since a pointer to a struct always points at its first member, you're safe to treat a Struct2 *
as a Struct1 *
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…