J
James Brown
All,
I have the following structure definition:
struct S
{
union U
{
double fval;
int ival;
} u;
};
Let's say I declare one like so:
struct S s;
s.u.fval = 5.0;
And later do this:
s.u.ival = (int)s.u.fval;
And the converse:
s.u.ival = 23;
s.u.fval = (double)s.u.ival;
I am unsure if it is legal to perform this conversion over the top of union
fields that share the same storage space? Can anyone clarify?
It is simple enough to change my code to not require a union, this is more
of a curiosity right now..
thanks,
James
I have the following structure definition:
struct S
{
union U
{
double fval;
int ival;
} u;
};
Let's say I declare one like so:
struct S s;
s.u.fval = 5.0;
And later do this:
s.u.ival = (int)s.u.fval;
And the converse:
s.u.ival = 23;
s.u.fval = (double)s.u.ival;
I am unsure if it is legal to perform this conversion over the top of union
fields that share the same storage space? Can anyone clarify?
It is simple enough to change my code to not require a union, this is more
of a curiosity right now..
thanks,
James