最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

function - Differences between pure, const, reproducible, unsequenced in C - Stack Overflow

programmeradmin3浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论