#include "stdio.h"
/* array to store data receeived from CAN Bus */
unsigned char a[8] = {0xCD, 0xEF, 0x12, 0x34, 0x50, 0x00, 0x00, 0x00};
typedef struct {
unsigned int a:12;
unsigned int b:12;
unsigned int c:12;
unsigned int unused:28;
}test;
test *tptr;
int main(void)
{
tptr = (test*)( (void*)&a); // is this line braking any aliasing rule
if(tptr->a == 0xCDE)
{
printf("\n data received ok");
}
return 0;
}
I recently learned about problems due to pointer aliasing in C. I want to know if the above code is breaking any rules. Could it lead to problems?
I know that the bitfield's order is machine and implementation dependent. My question, however, is regarding pointer aliasing rules, which I want to understand more clearly