|
The high-endian/low-endian will only be an issue if the data is being transferred to another machine. So for example, if any network code is involved, or permanent data files, then yes, you do need to serialize the data rather than just use casting.
Arrays are packed in C, so you shouldn't have any packing issues. This would become an issue if you were using structs for the data.
You can sometimes get alignment issues when converting pointers (though not in your example), particularly when casting pointers to char.
If you really have to do something like this, I'd suggest using void pointers rather than char pointers so that it is clear that the data type has been lost.
And if there is any possibility of using C++ (even if it is just a subset), there are nicer ways to do this that don't involve casting. Using C++ doesn't mean changing all the code to an object oriented model.
Code like your example indicates one of several things: (1) use of legacy library functions which cannot be changed (so they need to have a wrapper around them); (2) data which is going to be serialized (so it should be done in a platform independent way); or (3) trying to achieve object inheritance in a non-object based language (use pointers to implement inheritance, or move to C++).
|