...
This example compiles without warning. However, v_pointer
may be aligned on a one byte boundary. Once it is cast to an int *
, some architectures will require that the object is aligned on a four byte boundary. If int_ptr
is later dereferenced, the program may terminate abnormally.
One solution would be is to ensure that loop_ptr
points to an object returned by malloc()
, since that because this object is guaranteed to be aligned properly for any need. However, this is a subtlety that is easily missed when the program is modified in the future. It is cleaner to let the type system document the alignment needs.
...