I\'m trying to check some of my code for strict aliasing violations, but it looks like I\'ve missed something while trying to understand the strict aliasing rule.
Im
There is nothing inherently wrong with
sp = ( unsigned short * )&l;
For all the compiler knows, you might simply cast back the pointer to the correct type again.
There is also nothing inherently wrong with
*( sp ) = 1;
It's the combination of the two that's wrong.
The compiler just can't put the two together to tell you the combination is problematic (it is impossible in the general case, and not so easy in this particular case).
But
*( ( unsigned short * )&l ) = 1;
is far easier to detect, and hence the compiler does its best to do so.