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

本文标签: