Sequence Point - Examples of Ambiguity

Examples of Ambiguity

Consider two functions f and g. In C and C++, the + operator is not associated with a sequence point, and therefore in the expression f+g it is possible that either f or g will be executed first. The comma operator introduces a sequence point, and therefore in the code f,g the order of evaluation is defined: first f is called, and then g is called.

Sequence points also come into play when the same variable is modified more than once within a single expression. An often-cited example is the C expression i=i++, which apparently both assigns i its previous value and increments i. The final value of i is ambiguous, because, depending on the order of expression evaluation, the increment may occur before, after, or interleaved with the assignment. The definition of a particular language might specify one of the possible behaviors or simply say the behavior is undefined. In C and C++, evaluating such an expression yields undefined behavior.

Read more about this topic:  Sequence Point

Famous quotes containing the words examples of, examples and/or ambiguity:

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)

    It is hardly to be believed how spiritual reflections when mixed with a little physics can hold people’s attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.
    —G.C. (Georg Christoph)

    Unlike the ambiguity of life, the ambiguity of language does reach a limit.
    Mason Cooley (b. 1927)