logoalt Hacker News

sedictious • today at 8:35 PM • 0 replies • view on HN

I'd say C++ is so vast that you can keep on encountering bell curves like that. I start working on a project, building confidence in the subset of C++ I'm working with and when I start feeling good about myself, I'm hit with a completely foreign concept

cppquiz is a nice test beyond "trivia". There are a few hard questions addressing topics I've never encountered. For example:

```

#include <iostream>

volatile int a;

int main() { std::cout << (a + a); }

```

I would assume that here a is initialised to 0 since it has static lifetime so I'd expect this to just print 0. But the C++ standard specifies that:

> Reading an object designated by a volatile glvalue ([basic.lval]), modifying an object, calling a library I/O function, 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 (or a subexpression) in general includes both value computations (including determining the identity of an object for glvalue evaluation and fetching a value previously assigned to an object for prvalue evaluation) and initiation of side effects. When a call to a library I/O function returns or an access through a volatile glvalue is evaluated the side effect is considered complete, even though some external actions implied by the call (such as the I/O itself) or by the volatile access may not have completed yet.

and if you have side effects unsequenced relative to other side effects (as is the case with operations of the same operand), this is considered UB