TIOBE - C Coding Standard
|Synopsis:||Pointers must not be cast to have potentially stricter alignment.|
|Consider the following where a receiving pointer represents a type which has potentially stricter memory alignment criteria than that of the type being cast.
If, for a particular architecture, 'short' and 'int' were aligned as stated above then it is possible for 's' to have an address which does not represent a legal 'int' address. In other words, if the address contained in 's' was accessed as if it represented the location of an 'int' type then it is quite possible that an address exception would be generated.Note that casts which involve a strictly aligned type being converted to a less strict type and back again are guaranteed safe by the ANSI standard.
short * s; /* 2 byte aligned */
int * i; /* 4 byte aligned */
i = (int*)s; /* potentially mis-aligned */