liveBook · Manning

Indeterminate result

As explained in Modern C

An indeterminate result is an outcome for which the language standard defines the behavior but does not select one completely determined value or ordering.

Consider a complete C program that calls add(&a, &b) and add(&b, &a) as arguments to printf. Each call changes an object through a side effect, but the standard does not determine which call happens first. The behavior remains defined, while the final values and printed results can differ. section 17.2

Two valid outputs

The program can print “a = 8, b = 13” or “a = 11, b = 8”. These outputs reflect different permitted orders for the two function calls, not undefined behavior. section 17.2

TAKEAWAY 17.1: Side effects in functions can lead to indeterminate results. Do not assume an evaluation order merely because a compiler accepts the program; commonly used compilers can choose differently without warning. section 17.2

How Modern C covers it

How deep it goes
Works through competing outputs and relates them to indeterminate sequencing, then lists sequence points and further sequencing restrictions.
Examples
Uses an add function called twice inside printf, with outputs changing between “a = 8, b = 13” and “a = 11, b = 8”.
What you can do after
Evaluate/understand why differing outputs can still constitute defined behavior and avoid relying on an assumed call order.
How it connects
Connects side effects with function calls, evaluation order, sequencing, and sequence points.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.