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:

    There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring ‘em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.
    Bernard Mandeville (1670–1733)

    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 (1533–1592)

    Indeed, it is that ambiguity and ambivalence which often is so puzzling in women—the quality of shifting from child to woman, the seeming helplessness one moment and the utter self-reliance the next that baffle us, that seem most difficult to understand. These are the qualities that make her a mystery, the qualities that provoked Freud to complain, “What does a woman want?”
    Lillian Breslow Rubin (20th century)