I was reading up on this thread on pointer aliasing rules, and one answer gives the following example, which mentions a potential problem with endianness, I wanted to know if anyone could give me what the endianness problem is in the following code?
struct Msg
{
unsigned int a;
unsigned int b;
};
int main()
{
// Pass data to something; if the implementer of this API were
// strict-aliasing-aware, he would have taken a char*, not a unsigned int*
Msg* msg = new Msg();
msg->a = 1;
msg->b = 2;
// stupidBuffer is an alias for msg.
// yes I know there are endianess problems here (WHY??), but my API is stupid and
// only works for one platform
unsigned int* stupidBuffer = reinterpret_cast<unsigned int*>(msg);
SendToStupidApi( stupidBuffer );
}