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!
=== Up to C++03 === In C<ref>Annex C of the [[C99]] specification lists the circumstances under which a sequence point may be assumed.</ref> and C++,<ref>The 1998 C++ standard lists sequence points for that language in section 1.9, paragraphs 16–18.</ref> sequence points occur in the following places. (In C++, [[operator overloading|overloaded operators]] act like functions, and thus operators that have been overloaded introduce sequence points in the same way as function calls.) #Between evaluation of the left and right operands of the <code>&&</code> ([[logical conjunction|logical AND]]), <code>||</code> ([[logical disjunction|logical OR]]) (as part of [[short-circuit evaluation]]), and [[comma operator]]s. For example, in the expression {{code|2=c|1=*p++ != 0 && *q++ != 0}}, all side effects of the sub-expression {{code|2=c|1=*p++ != 0}} are completed before any attempt to access {{code|2=c|1=q}}. #Between the evaluation of the first operand of the [[ternary conditional operator]] and its second or third operand. For example, in the expression {{code|2=c|1=a = (*p++) ? (*p++) : 0}} there is a sequence point after the first {{code|2=c|1=*p++}}, meaning it has already been incremented by the time the second instance is executed. #At the end of a full expression. This category includes expression statements (such as the assignment {{code|2=c|1=a=b;}}), [[return statement]]s, the controlling expressions of {{code|2=c|1=if}}, {{code|2=c|1=switch}}, {{code|2=c|1=while}}, or {{code|2=c|1=do}}-{{code|2=c|1=while}} statements, and each of the three expressions in a <code>[[for loop#1972: C/C++|for]]</code> statement. #Before a function is entered in a function call. The order in which the arguments are evaluated is not specified, but this sequence point means that all of their side effects are complete before the function is entered. In the expression {{code|2=c|1=f(i++) + g(j++) + h(k++)}}, {{code|2=c|1=f}} is called with a parameter of the original value of {{code|2=c|1=i}}, but {{code|2=c|1=i}} is incremented before entering the body of {{code|2=c|1=f}}. Similarly, {{code|2=c|1=j}} and {{code|2=c|1=k}} are updated before entering {{code|2=c|1=g}} and {{code|2=c|1=h}} respectively. However, it is not specified in which order {{code|2=c|1=f()}}, {{code|2=c|1=g()}}, {{code|2=c|1=h()}} are executed, nor in which order {{code|2=c|1=i}}, {{code|2=c|1=j}}, {{code|2=c|1=k}} are incremented. If the body of {{code|2=c|1=f}} accesses the variables {{code|2=c|1=j}} and {{code|2=c|1=k}}, it might find both, neither, or just one of them to have been incremented. (The function call {{code|2=c|1=f(a,b,c)}} is ''not'' a use of the comma operator; the order of evaluation for {{code|2=c|1=a}}, {{code|2=c|1=b}}, and {{code|2=c|1=c}} is unspecified.) #At a function return, after the return value is copied into the calling context. (This sequence point is only specified in the C++ standard; it is present only implicitly in C.<ref>C++ standard, ISO 14882:2003, section 1.9, footnote 11.</ref>) #At the end of an [[initializer#C family of languages|initializer]]; for example, after the evaluation of {{code|2=c|1=5}} in the declaration {{code|2=c|1=int a = 5;}}. #Between each declarator in each declarator sequence; for example, between the two evaluations of {{code|2=c|1=a++}} in {{code|2=c|1=int x = a++, y = a++}}.<ref>C++ standard, ISO 14882:2003, section 8.3: "Each init-declarator in a declaration is analyzed separately as if it was in a declaration by itself."</ref> (This is ''not'' an example of the comma operator.) #After each conversion associated with an input/output format specifier. For example, in the expression {{code|2=c|1=printf("foo %n %d", &a, 42)}}, there is a sequence point after the {{code|1=%n}} is evaluated and before printing {{code|1=42}}.
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)