Articles & Books

Quick Q: Function not called in code gets called at runtime

Quick A: undefined behaviour can result in anything.

Recently on SO:

Function not called in code gets called at runtime

The program contains undefined behavior, as dereferencing a null pointer (i.e. calling foo() in main without assigning a valid address to it beforehand) is UB, therefore no requirements are imposed by the standard.

Executing never_called at runtime is a perfect valid situation when undefined behavior has been hit, it's as valid as just crashing (like when compiled with GCC). Okay, but why is Clang doing that? If you compile it with optimizations off, the program will no longer output "formatting hard disk drive", and will just crash...

Quick Q: Confused about vectors

Quick A: Do not confuse mathematical concepts with C++ terminology.

Recently on SO:

Confused about vectors

You are getting confused because the mathematical concept of a vector can mean a "collection of data" and that is what you were taught int v[10] was. The actual name for that in C++ (and most other languages) is an "array" not a vector.

The libraries referred to in C++ Primer have a class called "vector" which is an implementation of an array. They are similar, but not the same.

I hope that clears that up a bit. You are probably confused because you were taught that int v[10] is a vector, but it is "not really" in C++. It's an array. Use that term to refer to it. If you ever refer to it as a vector, you will confuse others and yourself.

C++ Tips of the Week

Google's internal C++ tips are going public:

Abseil Publishing Google's C++ "Tips of the Week"

By Tom Manshreck, Abseil and C++ Tech Writer

From the article:

Background: About five years ago, within Google we started publishing a series of C++ tips, about once a week, that became known as the “C++ Tips of the Week” (TotW). They became wildly successful, and we are still publishing them to this day (indicating that a language as rich as C++ will not deplete us of topics anytime soon).

Not only do we discuss the finer points of the language, but in true “tip” fashion, offer our advice or design preferences. The collective set of C++ TotW has become a canon within Google itself, cited thousands of times per week in code reviews and internal mailing list discussions. Often they are cited by number, and some have become known simply as “totw/110” or “totw/77”.

We’ve decided to expose most of these tips to the Abseil development community, and the C++ community at large.

A friendly type predicate—Andrzej KrzemieĊ„ski

To improve the error messages.

A friendly type predicate

by Andrzej Krzemieński

From the article:

This is a sequel to the previous post on writing a custom type predicate. One of the readers on Reddit made a very insightful observation. The user has implemented a type that she intends to use with our library, call it Calc. She passes it to the library function, and she gets the compiler error:

static assertion failed: X does not have a desired interface

But what is our type missing? In the previous post we were describing 3 constraints. A concept could have far more of them. The user has already made an effort to have Calc comply with the constraints, so there must be something tiny missing. Maybe there is a bug in the implementation of the predicate? But it is difficult to track what it is that the predicate does not like about our type. We could use some more specific information...

Speeding up the Build of C and C++ Projects

Many programmers know firsthand that C and C++ program builds very long. Someone solves this problem by sword-fighting at build time, someone is going to the kitchen to "grab some coffee". This article is for those who are tired of this, and who decided it is time to do something about it.

Speeding up the Build of C and C++ Projects

by Phillip Khandeliants

From the article:

If your operating system uses ELF format object files (Unix-like systems), you can replace the GNU ld linker with GNU gold. GNU gold comes with binutils starting from the version 2.19, and is activated by the flag -fuse-ld=gold. In CMake it can be activated, for example, by the following code.


Clang 5 in a Docker container for C++17 development—SolarianProgrammer

Very convenient to create a development environment without hassles.

Clang 5 in a Docker container for C++17 development

by SolarianProgrammer

From the article:

If you want to try the new C++17, using Clang in a Docker container, you are in the right place. Running Clang in a container has the advantage that it is light on resources and won’t mess with your underlying OS. The last point is especially important if your host operating system is macOS, on which it is a really bad idea to directly install a binary Clang other than the one that comes with Xcode. I’ve tested the approach presented in this article on Windows 10, macOS High Sierra and Ubuntu Linux.

Overload 142 is now available

ACCU’s Overload journal of December 2017 is out. It contains the following C++ related articles.

Overload 142 is now available

From the journal:

Too Fast! Too slow! Too right!!
Many products over-promise. Frances Buontempo muses on how to get things just right. by Frances Buontempo

CAS (Re)Actor for Non-Blocking Multithreaded Primitives
Lock free programming can be difficult. Sergey Ignatchenko shows how copy and swap can work for reactors. by Sergey Ignatchenko

A Design Example
Design issues cause problems. Charles Tolman considers an organising principle to get to the heart of the matter. by Charles Tolman

The Last Word in Patterns
What can you do in a single transaction in a database? Paul Grenyer writes us his Single CrUD pattern. by Paul Grenyer

Implementing Type-Classes as OCaml Modules
Type classes achieve overloading in functional paradigms. Shayne Fletcher implements some as OCaml modules. by Shayne Fletcher

Evolutionary Computing Frameworks for Optimisation
Evolutionary algorithms can find optimal solutions to problems. Aurora Ramírez and Chris Simons give us an overview. by Aurora Ramírez and Chris Simons