Can I thrust in GCC doing the right thing when casting to a wider type in C?

Segher Boessenkool segher@kernel.crashing.org
Sat Aug 3 13:59:00 GMT 2019


On Sat, Aug 03, 2019 at 09:30:59AM +0200, Aaron wrote:
> Can I thrust in GCC doing the right thing when casting to a wider type 
> in C, now and in the future?

Yes.  There can be bugs, of course.

> Unfortunately, it is not valid C due to the effective type rules. (6.5 
> Expression 7).

>                 // this is safe due to the check: if(... 
> above

No it's not.  It likely isn't valid code (unless d and s happen to
always point to things with effective type int here).

>                 *(unsigned*)d=*(const unsigned*)s; // <===== 
> line in question

If you don't like 6.5/7, and you don't mind slower code, you can use
-fno-strict-aliasing .


Segher



More information about the Gcc-help mailing list