I have two 32-bit integers and two 16-bit integers. How can I combine them into one 12-byte long array in the kernel?
char a[12];
char* b = &a[0];
int* c = (int*)b;
c[0] = n1;
c[1] = n2;
short* d = (short*)(b + 8);
d[0] = s1;
d[1] = s2;
Edit: when these statments stay in a function then there will be no strict aliasing problem.
Additionally if you want to learn more about aliasing find this function from GCC's source: c_common_get_alias_set
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments