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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html
and see how musl libc uses it in implementations of string functions:
(e.g. strlen)
http://git.musl-libc.org/cgit/musl/tree/src/string/strlen.c?id=4d0a82170a25464c39522d7190b9fe302045ddb2
(e.g. memmove)
http://git.musl-libc.org/cgit/musl/tree/src/string/memmove.c?id=4d0a82170a25464c39522d7190b9fe302045ddb2

(same for C++)

HTH.
Alexander



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux