August 2018

Win a free ticket for C++ on Sea!

The new, upcoming C++ conference "C++ on Sea" offers a free ticket.

Win a free ticket for C++ on Sea!

by C++ on Sea

About the competition:

For a brand new conference the interest in C++ on Sea already has been phenomenal!

Early Bird tickets are available and are already starting to sell - which is really exciting for us (and a little bit nerve wracking - especially after a technical hitch early on).

Amongst those that have heard of us the interest is definitely there, for which we are very grateful.

But we want to reach even more people - and that's where you come in. We'd like you to tweet about the conference.

CppCon 2017: Tools from the C++ eco-system to save a leg--Anastasia Kazakova

Have you registered for CppCon 2018 in September? Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2017 for you to enjoy. Here is today’s feature:

Tools from the C++ eco-system to save a leg

by Anastasia Kazakova

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

C++ gives you enough rope to shoot your leg off. Readable (and thus easy to maintain, easy to support) and error-free code in C++ is often hard to achieve. And while modern C++ standards bring lots of fantastic opportunities and improvements to the language, sometimes they make the task of writing high quality code even harder. Or can’t we just cook them right? Can the tools help?

In this talk I’ll highlight the main trickiness of C++, including readability problems, some real-world issues, problems that grow out of C++ context-dependent parsing. I’ll then try to guide you in how to eliminate them using tools from the C++ eco-system. This will cover code styles and supportive tools, code generation snippets, code analysis (including CLion’s inspections and Data Flow Analysis, C++ Code Guidelines and clang-tidy checks), refactorings. I will also pay some attention to unit testing frameworks and dependency managers as tools that are essential for the high quality code development.

Dependency Management for C++ (2) -- Hans Klabbers

Although I didn’t post anything lately, don’t worry – I’m still working on a proposal for dependency management.

Dependency Management for C++ (2)

by Hans Klabbers

From the article:

I arrived at the conclusion that not only dependency management needs to be taken into account and standardised. Also building software with the defined dependencies need to be taken into account when creating a standard for dependency management.

CppCast Episode 163: Sourcetrail with Eberhard Gräther

Episode 163 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Eberhard Gräther to discuss his work on Sourcetrail, a cross-platform source explorer for C++ code.

CppCast Episode 163: Sourcetrail with Eberhard Gräther

by Rob Irving and Jason Turner

About the interviewee:

Eberhard Gräther is software developer, user experience designer and founder at Coati Software. He started programming C++ during his undergraduate CS degree at Salzburg University of Applied Sciences, majoring in game development. During multiple internships in the Google Chrome Team he worked on tools for rendering performance analysis. He then specialized in Human Computer Interaction and developer tooling during a Master's degree, where he started working on Sourcetrail, a cross-platform source explorer for faster understanding of unfamiliar source code.

CppCon 2017: C++ atomics, from basic to advanced. What do they really do?--Fedor Pikus

Have you registered for CppCon 2018 in September? Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2017 for you to enjoy. Here is today’s feature:

C++ atomics, from basic to advanced. What do they really do?

by Fedor Pikus

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

C++11 introduced atomic operations. They allowed C++ programmers to express a lot of control over how memory is used in concurrent programs and made portable lock-free concurrency possible. They also allowed programmers to ask a lot of questions about how memory is used in concurrent programs and made a lot of subtle bugs possible.

This talk analyzes C++ atomic features from two distinct points of view: what do they allow the programmer to express? what do they really do? The programmer always has two audiences: the people who will read the code, and the compilers and machines which will execute it. This distinction is, unfortunately, often missed. For lock-free programming, the difference between the two viewpoints is of particular importance: every time an explicit atomic operation is present, the programmer is saying to the reader of the program "pay attention, something very unusual is going on here." Do we have the tools in the language to precisely describe what is going on and in what way it is unusual? At the same time, the programmer is saying to the compiler and the hardware "this needs to be done exactly as I say, and with maximum efficiency since I went to all this trouble."

This talk starts from the basics, inasmuch as this term can be applied to lock-free programming. We then explore how the C++ lock-free constructs are used to express programmer's intent clearly (and when they get in the way of clarity). Of course, there will be code to look at and to be confused by. At the same time, we never lose track of the fact that the atomics are one of the last resorts of efficiency, and the question of what happens in hardware and how fast does it happen is of paramount importance. Of course, the first rule of performance — "never guess about performance!" — applies, and any claim about speed must be supported by benchmarks.

If you never used C++ atomics but want to learn, this is the talk for you. If you think you know C++ atomics but are unclear on few details, come to fill these few gaps in your knowledge. If you really do know C++ atomics, come to feel good (or to be surprised, and then feel even better).

Quick Q: What are copy elision and return value optimization?

Quick A: they are common optimizations that a compiler can do behind the scenes to avoid copying in certain cases.

Recently on SO:

What are copy elision and return value optimization?

Copy elision is an optimization implemented by most compilers to prevent extra (potentially expensive) copies in certain situations. It makes returning by value or pass-by-value feasible in practice (restrictions apply).

It's the only form of optimization that elides (ha!) the as-if rule - copy elision can be applied even if copying/moving the object has side-effects.

The following example taken from Wikipedia:

struct C {
  C() {}
  C(const C&) { std::cout << "A copy was made.\n"; }
};

C f() {
  return C();
}

int main() {
  std::cout << "Hello World!\n";
  C obj = f();
}

Depending on the compiler & settings, the following outputs are all valid:

Hello World!
A copy was made.
A copy was made.
Hello World!
A copy was made.
Hello World!

This also means fewer objects can be created, so you also can't rely on a specific number of destructors being called. You shouldn't have critical logic inside copy/move-constructors or destructors, as you can't rely on them being called.

If a call to a copy or move constructor is elided, that constructor must still exist and must be accessible. This ensures that copy elision does not allow copying objects which are not normally copyable, e.g. because they have a private or deleted copy/move constructor.

C++17: As of C++17, Copy Elision is guaranteed when an object is returned directly:

struct C {
  C() {}
  C(const C&) { std::cout << "A copy was made.\n"; }
};

C f() {
  return C(); //Definitely performs copy elision
}
C g() {
    C c;
    return c; //Maybe performs copy elision
}

int main() {
  std::cout << "Hello World!\n";
  C obj = f(); //Copy constructor isn't called
}

CppCon 2017: How to break an ABI and keep your users happy--Gennadiy Rozental

Have you registered for CppCon 2018 in September? Registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2017 for you to enjoy. Here is today’s feature:

How to break an ABI and keep your users happy

by Gennadiy Rozental

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Technical debt is the bane of most established libraries, whether it is standard library or boost or local library developed in house. Paying this debt is expensive and in many cases seems infeasible.

As a result of several (justified at the time) decisions Google accumulated serious technical debt in how we use std::string. This became a blocking issue in our effort to open source Google’s common libraries.

To fix this we needed to break libstdc++ std::string ABI. This is the story of how we survived it kept Google still running.