Questions tagged [sequence-points]

Points in a program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed.

A sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed. They are often mentioned in reference to C and C++, because the result of some expressions can depend on the order of evaluation of their subexpressions. Adding one or more sequence points is one method of ensuring a consistent result, because this restricts the possible orders of evaluation. (from Wikipedia)

This tag should be used whenever the question is related to problems that are (eventually found to be) caused by ambiguous execution of subexpressions, which results in the difference of the expected result by novice programmers.

189 questions
3
votes
2 answers

Is the semicolon really a sequence point in C?

According to this answer, the following are the sequence points described in the standard: Between the evaluations of the function designator and actual arguments in a function call and the actual call; Between the evaluations of the first and…
Kushagr Jaiswal
  • 191
  • 1
  • 9
3
votes
2 answers

Undefined behavior in C

In this website, in the last section, they have provided f(i = -1, i = -1) as an example of undefined behavior due to unsequenced evaluation of subexpressions within function arguments. But since there is a sequence point after the evaluation of all…
Sourav Kannantha B
  • 2,860
  • 1
  • 11
  • 35
3
votes
2 answers

Evaluation Order of C Language

Is x+=x*=x undefined behavior? Can anyone explain this rule in Order of evaluation? What is "single evaluation"? What is the opposite of "single evaluation"? 14) With respect to an indeterminately-sequenced function call, the operation of…
3
votes
2 answers

C++ sequence points and changes to evaluation order in C++17

I am a bit confused about the way the changes to C++17 affect the rule that you should not modify one variable 2 times between sequence points. For example is this specified, unspecified or undefined in C++17? void func(int x, int y); int…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277
3
votes
1 answer

C++ cout behavior / order of execution

I was looking at some example questions of CPPInstitute's CPA-21-01 exam, and am a bit confused about Question #11. It states the following: What is the output of the following program? #include using namespace std; class A…
namezero
  • 2,203
  • 3
  • 24
  • 37
3
votes
3 answers

Will disabling interrupts protect a non-volatile variable or can reordering happen?

Suppose INTENABLE is a microcontroller's register that enables/disables interrupts, and I have it declared somewhere in my libraries as a volatile variable located at the appropriate address. my_var is some variable that is modified within one or…
tlongeri
  • 122
  • 1
  • 7
3
votes
2 answers

Sequence points in C++ and exceptions

Can compiler reorder variable setting and throw() op in C++? Or, does standard C++ 14882-1998 allows or prohibit compiler of this transform? For code: bool funct() { bool succeeded = false; bool res_throw = false; try { …
osgx
  • 90,338
  • 53
  • 357
  • 513
3
votes
2 answers

Does standard C++11 guarantee that temporary object passed to a function will have been created before function call?

Does standard C++11 guarantee that all 3 temporary objects have been created before the beginning performe the function? Even if temporary object passed as: object rvalue-reference passed only member of temporary…
Alex
  • 12,578
  • 15
  • 99
  • 195
3
votes
0 answers

Sequence point in the assignment operator

I already checked some other answers like: Sequence point within assignment operators or Undefined behavior and sequence points but I have still some doubt about the following part: In all cases, the assignment is sequenced after the value…
andre3312
  • 147
  • 7
3
votes
2 answers

Sequence Points and Method Chaining reloaded

I've read this: Undefined behavior and sequence points Undefined behavior and sequence points reloaded Sequence Points and Method Chaining GCC bug? Chaining methods, broken sequence point ...but I'm still not sure how this should behave: int…
rr-
  • 14,303
  • 6
  • 45
  • 67
3
votes
1 answer

C sequence points within expression containing function calls and post-increments

What is printed by the following code? #include int f(int x) { printf("%d", x); return 1; } int main() { int i = 0; f(i++) && f(i++); } Is it guaranteed to be 01, or could it be 00 with both of the post-increments happening…
Neil G
  • 32,138
  • 39
  • 156
  • 257
3
votes
4 answers

Is this a undefined behaviour or normal output

This is a very simple question but even have some doubt in sequence point. int a[3] = {1,2,4}; printf("%d",++a[1]); o/p 3 Is this a valid c statement, I am getting output 3, which means it is same as ++(a[1]) But how is this possible as we have a…
pradipta
  • 1,718
  • 2
  • 13
  • 24
3
votes
2 answers

Sequencing in composite conditional expression

The if statement in the following sample comes from an old project I am trying to build again. I am sorry this is not a verifiable sample in the sense that it does not reproduce the error, it compiles fine by itself. enum S { }; struct R { S…
iavr
  • 7,547
  • 1
  • 18
  • 53
3
votes
2 answers

Sequence point && operator

For C++03, the standard says, that between left and right operand of && operator there is a sequence point, so that all side effects of left operator have taken place before right operator is accessed. So int i = 0; if (++i && i--) std::cout <<…
3
votes
1 answer

Is foo(i++) + foo(i++) undefined in ANSI C?

Here's an example snippet: int i = 4,b; b = foo(i++) + foo(i++); I'm pretty certain it's not undefined, because there is a sequence point before the invocation of foo. However, if I compile the code with the -Wall flag a compiler warning is…
JustinBlaber
  • 4,629
  • 2
  • 36
  • 57