On 2025-12-28 00:57, Jₑₙₛ Gustedt wrote:
Why is f not idempotent if there's no requirement that f must return?
Because replacing a call `f(x)` with two calls `(f(x), f(x))` has the
program behave differently.

Yes, that's a normal English-language meaning of "idempotent". But it's not C23's definition. C23's definition does not directly say anything like "has the program behave differently". Instead, it refers to "observable state" and this use of "observable" follows a previous-paragraph definition of "observable" - which "observable state" could reasonably be seen to referring to (though apparently not?).

If the standard's definition of idempotent/reproducible would be changed to talk more formally about what it means for a program to "behave differently" and why that matters for idempotency/reproducibility, that would clear up a lot of the confusion here. It would also make the motivation clearer: the motivation is to let a compiler elide a call to a function if either the state has not changed, or some other less-well-defined condition holds. Stating that motivation (perhaps in a footnote) would help clear up things further.

Reply via email to