All Questions

671
votes
13answers
54348 views

Why are these constructs (using ++) undefined behavior in C?

#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...
863
votes
4answers
84731 views

Undefined behavior and sequence points

What are "sequence points"? What is the relation between undefined behaviour and sequence points? I often use funny and convoluted expressions like a[++i] = i;, to make myself feel better. Why shoul...
78
votes
5answers
10014 views

Undefined behavior and sequence points reloaded

Consider this topic a sequel of the following topic: Previous installment Undefined behavior and sequence points Let's revisit this funny and convoluted expression (the italicized phrases are...
24
votes
4answers
2000 views

sequence points in c

A sequence point in imperative programming 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 ...
16
votes
2answers
3066 views

Unsequenced value computations (a.k.a sequence points)

Sorry for opening this topic again, but thinking about this topic itself has started giving me an Undefined Behavior. Want to move into the zone of well-defined behavior. Given int i = 0; int v[10];...
22
votes
7answers
12976 views

How do Prefix (++x) and Postfix (x++) operations work?

Can someone tell me how prefix / postfix operators really work? I've been looking online a lot but haven't found anything. From what I can tell prefex first increments, then does the operation and t...
53
votes
3answers
1352 views

In C99, is f()+g() undefined or merely unspecified?

I used to think that in C99, even if the side-effects of functions f and g interfered, and although the expression f() + g() does not contain a sequence point, f and g would contain some, so the behav...
6
votes
3answers
619 views

Sequence points and side effects in C

In this C-FAQ it is give about sequence point; The Standard states that; Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluat...
20
votes
5answers
1506 views

Why does the expression a = a + b - ( b = a ) give a sequence point warning in c++?

Following is the test code: int main() { int a = 3; int b = 4; a = a + b - (b = a); cout << "a :" << a << " " << "b :" << b << "\n"; retu...
26
votes
6answers
1689 views

Is this code well-defined?

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 ty...

Previous Next