Skip to main content
Stack Overflow
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
12 votes
3 answers
2k views

This answer says that i = 1; f(i++, i) will not evaluate to f(2, 2) since C++17. However, I'm struggling to understand why this would have been possible before C++17. What operations, and in what ...
3 votes
5 answers
296 views

tl;dr I have a program that "works", but does so in part via unsequenced behavior. I recognize that code with unsequenced behavior can technically do anything - however, it has to do ...
4 votes
2 answers
137 views

The standard states that the behavior of unsequenced operations that have side effect on the same memory location is undefined [intro.execution§10]. Does the following code have undefined behavior, ...
10 votes
1 answer
233 views

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 ...
2 votes
0 answers
129 views

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 of ...
Kyle's user avatar
  • 1,116
4 votes
3 answers
262 views

Consider a situation where we have the following functions: // A function with two parameters. void AcceptTwoInts(int, int); // Two functions that accept an integer and return another integer. int ...
5 votes
2 answers
167 views

I was puzzled by the fact that CPPReference says that postincrement’s value evaluation is sequenced before its side-effect, but preincrement has no such guarantee. I have now come up with an example ...
0 votes
3 answers
181 views

Suppose I have a weired add function which does an addition and an increment then stores the result to somewhere else. void add(const int* a, const int* b, int* c) { *c = (*a)++ + *b; } If I pass ...
1 vote
2 answers
236 views

Inspired by this SO post, I am wondering whether the below snippet causes UB as both add_func() and mul_func() could modify counter concurrently and in an unspecified order: int counter = 0; int ...
1 vote
3 answers
146 views

5.1.2.3 defines the following: In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce ...
2 votes
1 answer
190 views

I have this simple little code: #include <iostream> int Add (int x, int y) { std::cout << "In Add(), received " <<x<< " and " <<y<< "\...
33 votes
3 answers
3k views

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 ...
4 votes
1 answer
145 views

#include <stdio.h> int main(void) { int a = 0, b = 1; a = (a = 5) && (b = 0); printf("%d", a); printf("%d", b); } The value of variable a is getting ...
32 votes
3 answers
2k views

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 ...
0 votes
0 answers
125 views

I attempted to write a function that increments an unsigned integer and checks if the result overflowed, by comparing the old value of the integer with the value after incrementing: unsigned ...

15 30 50 per page
1
2 3 4 5
...
14

AltStyle によって変換されたページ (->オリジナル) /