• Create Account

### #ActualKhatharr

Posted 25 March 2013 - 03:44 AM

The thing is, I don't really see a problem with the cast. As long as the union is being formed correctly by the compiler it shouldn't cause any kind of problem. Just because it's not defined by the C++ standard doesn't necessarily mean it's anathema to all who dare.

In fact...

http://www.cplusplus.com/doc/tutorial/other_data_types/

says...

One of the uses a union may have is to unite an elementary type with an array or structures of smaller elements. For example:

union mix_t {
long l;
struct {
short hi;
short lo;
} s;
char c[4];
} mix;

As long as you're aware of the potential problems involved in union access, type puns, packing, alignment, endianness - none of which should be an issue here - the behavior should be consistent.

I don't understand how std::memcpy relates to this?

### #1Khatharr

Posted 25 March 2013 - 03:37 AM

The thing is, I don't really see the problem with the cast. As long as the union is being formed correctly by the compiler it shouldn't cause any kind of problem. Just because it's not defined by the C++ standard doesn't necessarily mean it's anathema to all who dare.

In fact...

http://www.cplusplus.com/doc/tutorial/other_data_types/

says...

One of the uses a union may have is to unite an elementary type with an array or structures of smaller elements. For example:

1
2
3
4
5
6
7
8

union mix_t {
long l;
struct {
short hi;
short lo;
} s;
char c[4];
} mix;

As long as you're aware of the potential problems involved in union access, type puns, struct packing and alignment (none of which are an issue here), the behavior should be consistent.

PARTNERS