Is pointer comparison undefined or unspecified behavior in C++?

Note that pointer subtraction and pointer comparison are different operations with different rules. C++14 5.6/6, on subtracting pointers: Unless both pointers point to elements of the same array object or one past the last element of the array object, the behavior is undefined. C++14 5.9/3-4: Comparing pointers to objects is defined as follows: If two … Read more

Does this code from “The C++ Programming Language” 4th edition section 36.3.6 have well-defined behavior?

The code exhibits unspecified behavior due to unspecified order of evaluation of sub-expressions although it does not invoke undefined behavior since all side effects are done within functions which introduces a sequencing relationship between the side effects in this case. This example is mentioned in the proposal N4228: Refining Expression Evaluation Order for Idiomatic C++ … Read more

Can I take the address of a function defined in standard library?

Short answer No. Explanation [namespace.std] says: Let F denote a standard library function ([global.functions]), a standard library static member function, or an instantiation of a standard library function template. Unless F is designated an addressable function, the behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a … Read more

Undefined, unspecified and implementation-defined behavior

Undefined behavior is one of those aspects of the C and C++ language that can be surprising to programmers coming from other languages (other languages try to hide it better). Basically, it is possible to write C++ programs that do not behave in a predictable way, even though many C++ compilers will not report any … Read more