Consider I have a typedef with bit fields as below.
typedef struct VIN_oCAN01_3abd61be
{
uint64_t var1:24;
uint64_t var2:4;
uint64_t var3:4
}__attribute__((packed))Message;
And I receive uint8_t buffer as below.
uint8_t buffer[4] = {0x1,0x2,0x3,0x14};
Currently in my production program my team is suggesting below approach.
Message *ptrMsg = (Message *)buffer;
That is, assigning uint8_t buffer to Message type pointer.
I had suggested that proposed approach does not follow strict aliasing rule and instead we should do as below.
Message msg;
memcpy(&msg,buffer, sizeof(msg));
Note there is no option of copying the buffer to structure manually(member by member) as structure is very big.
Is my understanding is correct? If so can you please provide the standard doc which I can use to prove my point.