TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
TIOBE - C Coding Standard

Guideline:  6.9#2Checked automatically with code checker

Synopsis:Pointers should not be type cast in general.
Severity Level:4

Consider the following where a receiving pointer represents a type which has potentially stricter memory alignment criteria than that of the type being cast.


short * s; /* 2 byte aligned */
int * i; /* 4 byte aligned */
i = (int*)s; /* potentially mis-aligned */
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.