Why are Standard iterator ranges [begin, end) instead of [begin, end]?

The best argument easily is the one made by Dijkstra himself: You want the size of the range to be a simple difference end − begin; including the lower bound is more “natural” when sequences degenerate to empty ones, and also because the alternative (excluding the lower bound) would require the existence of a “one-before-the-beginning” sentinel value. … Read more

Effects of the extern keyword on C functions

We have two files, foo.c and bar.c. Here is foo.c #include <stdio.h> volatile unsigned int stop_now = 0; extern void bar_function(void); int main(void) { while (1) { bar_function(); stop_now = 1; } return 0; } Now, here is bar.c #include <stdio.h> extern volatile unsigned int stop_now; void bar_function(void) { if (! stop_now) { printf(“Hello, world!\n”); … Read more

Array placement-new requires unspecified overhead in the buffer?

Update Nicol Bolas correctly points out in the comments below that this has been fixed such that the overhead is always zero for operator new[](std::size_t, void* p). This fix was done as a defect report in November 2019, which makes it retroactive to all versions of C++. Original Answer Don’t use operator new[](std::size_t, void* p) … Read more

Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

Yes, it’s legal. From the C99 draft standard: §6.5.2.1, paragraph 2: A postfix expression followed by an expression in square brackets [] is a subscripted designation of an element of an array object. The definition of the subscript operator [] is that E1[E2] is identical to (*((E1)+(E2))). Because of the conversion rules that apply to … Read more