Question

Currently there are two things that may change between invocations of a function: the return value, and the external states. I understand that if the external states changes, the function is not idempotent. However, it seems controversial whether the return value is required to stay the same. For example, is the below function idempotent?

int foo = 1; // global
int bar() {
    int ret_val = foo;
    foo = 5;
    return ret_val; // 1, 5, 5, 5...
}

Or is there consensus over this?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top