Should I worry about the alignment during pointer casting?
问题 In my project we have a piece of code like this: // raw data consists of 4 ints unsigned char data[16]; int i1, i2, i3, i4; i1 = *((int*)data); i2 = *((int*)(data + 4)); i3 = *((int*)(data + 8)); i4 = *((int*)(data + 12)); I talked to my tech lead that this code may not be portable since it's trying to cast a unsigned char* to a int* which usually has a more strict alignment requirement. But tech lead says that's all right, most compilers remains the same pointer value after casting, and I