Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Sequence point
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples of ambiguity== Consider two [[subroutine|function]]s <code>f()</code> and <code>g()</code>. In C and C++, the <code>+</code> operator is not associated with a sequence point, and therefore in the [[expression (computer science)|expression]] <code>f()+g()</code> it is possible that either <code>f()</code> or <code>g()</code> will be executed first. The comma operator introduces a sequence point, and therefore in the code <code>f(),g()</code> the order of evaluation is defined: first <code>f()</code> is called, and then <code>g()</code> 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 (programming language)|C]] expression <code>i=i++</code>, which apparently both assigns <code>i</code> its previous value and increments <code>i</code>. The final value of <code>i</code> 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 behavior|undefined]]. In C and C++, evaluating such an expression yields undefined behavior.<ref>Clause 6.5#2 of the [[C99]] specification: "Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored."</ref> Other languages, such as [[C Sharp (programming language)|C#]], define the [[order of operations|precedence]] of the assignment and increment operator in such a way that the result of the expression <code>i=i++</code> is guaranteed.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)