admin管理员组文章数量:1122870
Recently C23 added two new attributes: unsequenced
and reproducible
, which are now supported by GCC alongside the existing pure
and const
.
I am slightly confused by the exact differences between all of them, and all of the sources I could find only compared one or two of them, not all four at once.
Is the following understanding I have of them correct?
Attribute | Side Effects | Output | Read Globals [0] | Write Globals [0] | Read Pointer Args | Write Pointer Args | Examples | Optimisations |
---|---|---|---|---|---|---|---|---|
Pure | no | return | yes [1] | no | yes | no | strlen, memcpy |
Elide calls where globals and args have not changed |
Const | no | return | const [2] | no | const [2] | no | abs |
All calls with the same arguments have the same value; evaluate at compile-time |
Unsequenced | yes | return | const | no | yes | no | strlen |
Reorder calls |
Reproducible | yes | return or args | const | no | yes | yes | memcpy |
Elide repeated calls with the same arguments |
None | yes | return or args | yes | yes | yes | yes | printf |
None |
本文标签:
版权声明:本文标题:function - Differences between pure, const, reproducible, unsequenced in C - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736117670a1905745.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论