From ISO/IEC 9899:201x section 5.1.2.3 Program execution paragraph 2:
Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment. Evaluation of an expression in general includes both value computations and initiation of side effects. Value computation for an lvalue expression includes determining the identity of the designated object.
The paragraph says that "modifying an object" is a side effect. It means that the following code:
int x;
x = 1;
has a side effect which is the x = 1 as it is modifies the object x.
However, according to wikibooks on C Programming:
In C and more generally in computer science, a function or expression is said to have a side effect if it modifies a state outside its scope or has an observable interaction with its calling functions or the outside world. By convention, returning a value has an effect on the calling function, but this is usually not considered as a side effect.
Some side effects are:
- Modification of a global variable or static variable
- Modification of function arguments
- Writing data to a display or file
- Reading data
- Calling other side-effecting functions
So, who is right? is x = 1 really a side effect? even though it does not change anything outside it's scope? or am I wrongly interpreted the standard?
x = 1is 1; its side-effect is assigning 1 to x. You can use the value in a larger expression (y = 4 - (x = 1)) but you cannot depend on order of execution of side-effects (y = (x = 4) + (x = 2); /* y == 6; x == ?? */) - pmg