When does invoking a member function on a null instance result in undefined behavior?

Both (a) and (b) result in undefined behavior. It’s always undefined behavior to call a member function through a null pointer. If the function is static, it’s technically undefined as well, but there’s some dispute. The first thing to understand is why it’s undefined behavior to dereference a null pointer. In C++03, there’s actually a … Read more

What is “callback hell” and how and why does RX solve it?

1) What is a “callback hell” for someone who does not know javascript and node.js ? This other question has some examples of Javascript callback hell: How to avoid long nesting of asynchronous functions in Node.js The problem in Javascript is that the only way to “freeze” a computation and have the “rest of it” … Read more

Is it safe to push_back an element from the same vector?

It looks like http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-closed.html#526 addressed this problem (or something very similar to it) as a potential defect in the standard: 1) Parameters taken by const reference can be changed during execution of the function Examples: Given std::vector v: v.insert(v.begin(), v[2]); v[2] can be changed by moving elements of vector The proposed resolution was that this … Read more

C++ zero initialization – Why is `b` in this program uninitialized, but `a` is initialized?

The issue here is pretty subtle. You would think that bar::bar() = default; would give you a compiler generated default constructor, and it does, but it is now considered user provided. [dcl.fct.def.default]/5 states: Explicitly-defaulted functions and implicitly-declared functions are collectively called defaulted functions, and the implementation shall provide implicit definitions for them ([class.ctor] [class.dtor], [class.copy.ctor], … Read more

What happens if you static_cast invalid value to enum class?

What is color set to according to the standard? Answering with a quote from the C++11 and C++14 Standards: [expr.static.cast]/10 A value of integral or enumeration type can be explicitly converted to an enumeration type. The value is unchanged if the original value is within the range of the enumeration values (7.2). Otherwise, the resulting … Read more

How do I make an infinite empty loop that won’t be optimized away?

The C11 standard says this, 6.8.5/6: An iteration statement whose controlling expression is not a constant expression,156) that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a for statement) its expression-3, may be assumed by the implementation … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)