The answer in the another question: Strict aliasing rule and 'char *' pointers says that using a char*
to examine the binary contents of a T
object is ok. But using a T*
to overlay on a char buffer is not ok.
Now I have a function that takes a char buffer with binary data. And does things like this while reading it:
// unsigned char *pData used to walk through the buffer.
uint32_t value = *(unit32_t*)pData;
pData += 4;
If I break the strict aliasing by doing this, what other, more effective ways available? Will compilers optimize memcpy calls when they are called with small amount of bytes?