The safest, most portable way to convert POD (i.e. C compatible structs) types to unsigned char pointers is not by using reinterpret_cast
but by using static_cast
(C++0x fixes this and empowers reinterpret_cast to unambiguously have the same portable semantics as the following line of code):
unsigned char *uc_ptr2 = static_cast<unsigned char*>(static_cast<void*>(uc_ptr));
But for all practical purposes, even though the C++03 standard is thought to be somewhat ambiguous on the issue (not so much when converting pointers of class types, but when converting pointers of non-class types to 'unsigned char*'), most implementations will do the right thing if you do use reinterpret_cast
as so:
unsigned char *uc_ptr2 = reinterpret_cast<void*>(uc_ptr);
I suspect that you should be fine with alignment issues since your struct contains unsigned chars which can be aligned at any byte, so the compiler won't insert any packing between the members (but strictly speaking, this is implementation dependent, so use caution).