optimizations

std::array in C++ isn't slower than array in C

In my previous article on arrays, some readers expressed concern that std::array might be slower than the built-in C array. Several sources of truth exist on this matter, and today we'll go through each of them. Let's first find out what the standard states about it, then look at the std::array implementations in libc++ and libstdc++, and finally look at the assembler of some operations on these objects. Oh, and we'll top it off with benchmarking, of course.

std::array in C++ isn't slower than array in C

by Anton Tretyakov

From the article:

Let's get to the bottom of this. LLVM has a hardening mechanism called _LIBCPP_HARDENING_MODE. We can use it to enable additional checks depending on the mechanism level, which has a total of four levels. Enabling the weakest one removes the checks from the code. In other cases, there may or may not be a check, depending on the check and the level of the mode. We'll prove it. To understand what expands to what, we need to look at the source code. There, we see that depending on the given value of _LIBCPPP_HARDENING_MODE, _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS may expand to _LIBCPPP_ASSERT.

C++Now Announces Closing Keynote by John Regehr

C++Now 2018 will be held in Aspen, May 6–11, 2018.

Closing Keynote Announced: John Regehr on Undefined Behavior and Compiler Optimizations

From the announcement:

John is a professor of computer science at the University of Utah, where his research group creates tools for making software more efficient and correct. One of his projects is Csmith, a tool that generates random C programs. Why? To test compilers, of course. Csmith has been used to find more than 500 previously unknown bugs in production-quality compilers.

John will share some of the insights he’s gained from his research into compilers.

He will discuss what undefined behavior means to the compiler and how compiler writers use it in surprising ways generate better code.