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

Alexander Monakov
Sat Aug 3 07:53:00 GMT 2019

On Sat, 3 Aug 2019, Aaron wrote:

> I am afraid LTO or other upcoming methods of code-improvementwill bring grief
> on us.
> Why should someone want do write such code? Answer: speed
> Unfortunately, it is not valid C due to the effective type rules. (6.5
> Expression 7).

You are correct that such code is invalid and can be observably broken with LTO.

GCC supports the 'may_alias' type attribute to aid in writing such code. You can
refer to documentation at
and see how musl libc uses it in implementations of string functions:
(e.g. strlen)
(e.g. memmove)

(same for C++)


More information about the Gcc-help mailing list