another -Wunsequenced topic

David Chisnall theraven at FreeBSD.org
Tue Jul 9 08:13:39 UTC 2013


On 9 Jul 2013, at 05:40, Tim Kientzle <tim at kientzle.com> wrote:

> However, this does have an implicit redundant store,
> so changing it to
> 
>    ptr = func(ptr + 1);
> 
> is still a good idea, just not for the reason Clang was claiming.

If the compiler can tell that ptr has not escaped, then it will elide the redundant store (typically, it will be gone as long as ptr is a local and its address has not been passed out of the function), so there should be no change to the generated code.

However, I still agree that it is good style, because if I read the original code I would be left wondering what the original programmer expected the incremented value of ptr++ to be visible to and suspect a more subtle error.  

David

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 881 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/freebsd-current/attachments/20130709/5bcd35ca/attachment.sig>


More information about the freebsd-current mailing list