sequence-points Questions
2
Solved
In this recent question, some code was shown to have undefined behavior:
a[++i] = foo(a[i-1], a[i]);
because even though the actual call of foo() is a sequence point, the assignment is unsequenc...
Brainwashing asked 22/8, 2017 at 10:0
1
Consider the following C code:
const int array[100];
int i = 0;
int x;
int get_next(void) {
return array[i++];
}
int foo(void) {
return get_next() + get_next();
}
Assuming that i == 0 when foo...
Haywood asked 31/5, 2024 at 3:20
0
I am looking at the C23 draft standard, but I think this would apply in C11 as well. There are several guarantees about sequence points in relation to function calls in C, such as before the return...
Champaigne asked 23/5, 2024 at 4:17
3
Solved
In the following type of code is there a sequence point between each variable construction, or is the result undefined?
int a = 0;
int b = a++, c = a++;
I wasn't able to find in the standard a s...
Fadden asked 20/6, 2011 at 15:55
7
Solved
This code is taken from a discussion going on here.
someInstance.Fun(++k).Gun(10).Sun(k).Tun();
Is this code well-defined? Is ++k in Fun() evaluated before k in Sun()?
What if k is user-defined...
Billingsgate asked 17/1, 2011 at 3:17
3
Solved
Does the definition int a = 0, b = a++, c = a++; have defined behavior in C?
Or almost equivalently, does the comma in an object definition introduce a sequence point as for the comma operator in e...
Schaper asked 9/8, 2023 at 12:10
3
Solved
I was reading C Programming Language and found this sentence:
The commas that separate ... variables in declarations ... are not comma operators, and do not guarantee left to right evaluation.
...
Popelka asked 10/9, 2016 at 23:14
15
Solved
#include <stdio.h>
int main(void)
{
int i = 0;
i = i++ + ++i;
printf("%d\n", i); // 3
i = 1;
i = (i++);
printf("%d\n", i); // 2 Should be 1, no ?
volatile int u = 0;
u = u++ + ++u;...
Jacobinism asked 4/6, 2009 at 9:17
3
Solved
In the following code a member function set() is called on a model, which is a null pointer. This would be undefined behavior. However, the parameter of the member function is a result of another f...
Aleksandrovsk asked 9/5, 2023 at 8:29
3
Solved
I keep finding more idioms that lend themselves to std::exchange.
Today I found myself writing this in an answer:
do {
path.push_front(v);
} while (v != std::exchange(v, pmap[v]));
I like it a lo...
Homovec asked 28/11, 2022 at 13:52
4
Solved
Is there any good reason for operator = not being a sequence point? Both in C and C++.
I have trouble thinking about an counter-example.
Deceive asked 6/12, 2010 at 1:30
1
Solved
#include <iostream>
int& addOne(int& x)
{
x += 1;
return x;
}
int main()
{
int x {5};
addOne(x) = x;
std::cout << x << ' ' << addOne(x);
}
I'm currently in t...
Park asked 29/1, 2022 at 20:10
1
Solved
Originally, I presented a more complicated example, this one was proposed by @n. 'pronouns' m. in a now-deleted answer. But the question became too long, see edit history if you are interested.
Has...
Swimmingly asked 4/10, 2020 at 13:54
3
Solved
Wikipedia says that:
In computer science, an operation, function or expression is said to have a side effect if it modifies some state variable value(s) outside its local environment, that is to...
Irrelevant asked 2/6, 2020 at 8:57
2
A line of code that I naively thought would translate fairly literally between Perl 6 and Perl 5 in fact did not, due to differences in how a post-increment variable is being handled.
This Perl 6 ...
Supersensual asked 5/5, 2019 at 16:35
4
Solved
Given the following program:
#include <stdio.h>
int main(void)
{
int i = 1, j = 2;
int val = (++i > ++j) ? ++i : ++j;
printf("%d\n", val); // prints 4
return 0;
}
The initialization...
Chard asked 14/3, 2019 at 19:23
2
Solved
After stumbling across the question "Why are these constructs using pre and post-increment undefined behavior?" today I decided to grab the newest draft for the next C standard I could find and rea...
Bascom asked 25/11, 2018 at 14:22
4
Solved
I know that writing something like
++a = a++;
Is not only unreadable but also violates the c/c++ sequence points.
Where do these limitations come from? How can one see those 'problems' before f...
Enshrine asked 25/6, 2012 at 17:47
1
Solved
I read in the C++17 Standard $8.5.7.4:
The expression E1 is sequenced before the expression E2.
for shift operators.
Also cppreference rule 19 says:
In a shift operator expression E1<>E2, ...
Isocline asked 10/8, 2018 at 10:48
3
Solved
the following code:
myQueue.enqueue('a');
myQueue.enqueue('b');
cout << myQueue.dequeue() << myQueue.dequeue();
prints "ba" to the console
while:
myQueue.enqueue('a');
myQueue.enqu...
Quesada asked 24/1, 2010 at 22:44
5
Solved
In the C and C++ languages, the arr[i] = i++; statement invokes undefined behavior. Why does the statement i = i + 1; not invoke undefined behavior?
Loner asked 3/6, 2017 at 6:51
1
Solved
Just learned here that -Wsequence-point comiplation flag will pop a warning when the code can invoke UB. I tried it on a statement like
int x = 1;
int y = x+ ++x;
and it worked very nicely. Unt...
Placida asked 14/5, 2017 at 11:18
2
Solved
I thought I understand how sequence points work in C++, but this GeeksQuiz question puzzled me:
int f(int &x, int c) {
c = c - 1;
if (c == 0) return 1;
x = x + 1;
return f(x, c) * x;
}
in...
Fishnet asked 7/10, 2016 at 9:50
3
Solved
Undefined behavior and sequence points
The link above is talking about sequence point and side effect in C++.
In a word, it means that between two sequence points, if we have more than one side e...
Clyve asked 6/10, 2016 at 2:9
4
Solved
Following is the test code:
int main()
{
int a = 3;
int b = 4;
a = a + b - (b = a);
cout << "a :" << a << " " << "b :" << b << "\n";
return 0;
}
Compi...
Chinn asked 9/11, 2012 at 23:48
1 Next >
© 2022 - 2025 — McMap. All rights reserved.