L
lovecreatesbeauty
Suppose, I have two customized types here:
typedef struct
{
int dt_qual;
int dec_exp;
int dec_pos;
int dec_ndgts;
/* char dec_dgts[8]; */
} datetime;
typedef struct
{
int dt[4]; /* [6] */
} dtime;
1. Can value of variables of these two types above be transformed each
other correctly always? Suppose I copy bytes from variable typed
datetime to variable typed dtime using memcpy(), can I get the value of
fields in struct datetime through dtime.dt? For example:
datetime *pdate = (datetime *)malloc(sizeof(*pdate));
dtime sdate;
/* initializaion omitted */
memcpy(&sdate, pdate, sizeof(*pdate));
then, are the following conditional expressions true?
sdate.dt[0] == pdate->dt_qual;
sdate.dt[1] == pdate->dec_exp;
sdate.dt[2] == pdate->dec_pos;
sdate.dt[3] == pdate->dec_ndgts;
2. Type convertions are valid for many data types, but why convertions
(even explicitly) between structs (non-scalar types?...) are forbiden?
What's the consideration under the limitation?
typedef struct
{
int dt_qual;
int dec_exp;
int dec_pos;
int dec_ndgts;
/* char dec_dgts[8]; */
} datetime;
typedef struct
{
int dt[4]; /* [6] */
} dtime;
1. Can value of variables of these two types above be transformed each
other correctly always? Suppose I copy bytes from variable typed
datetime to variable typed dtime using memcpy(), can I get the value of
fields in struct datetime through dtime.dt? For example:
datetime *pdate = (datetime *)malloc(sizeof(*pdate));
dtime sdate;
/* initializaion omitted */
memcpy(&sdate, pdate, sizeof(*pdate));
then, are the following conditional expressions true?
sdate.dt[0] == pdate->dt_qual;
sdate.dt[1] == pdate->dec_exp;
sdate.dt[2] == pdate->dec_pos;
sdate.dt[3] == pdate->dec_ndgts;
2. Type convertions are valid for many data types, but why convertions
(even explicitly) between structs (non-scalar types?...) are forbiden?
What's the consideration under the limitation?