When I today read the C Standard, it says about side effects
Accessing a volatile object, modifying an object, modifying a file, or calling a function that does any of those operations are all side effects
and the C++ Standard says
Accessing an object designated by a volatile glvalue (3.10), modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects
Hence because both forbid unsequenced side effects to occur on the same scalar object, C allows the following, but C++ makes it undefined behavior
int a = 0;
volatile int *pa = &a;
int b = *pa + *pa;
Am I reading the specifications correctly? And what is the reason for the discrepancy, if so?
*pais an lvalue designating avolatilequalified object. - Jens Gustedtint. Interestingly if you would have usedvolatile int *pa = calloc(sizeof *pa, 1);the effective type would volatile. - Jens Gustedt