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:
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“Unlike the ambiguity of life, the ambiguity of language does reach a limit.”
—Mason Cooley (b. 1927)