Articles & Books

Be Wise, Sanitize - Keeping Your C++ Code Free From Bugs--Marin Peko

All is in the title.

Be Wise, Sanitize - Keeping Your C++ Code Free From Bugs

by Marin Peko

From the article:

For all of the losses it has inflicted, this pandemic has at least made us more conscious about our personal hygiene.

We’re spraying spaces, surfaces and our hands way more often, so why not sanitize our code while we’re at it? After all, software runs the world, and bugs that cause programs to malfunction can cause serious damage – much like their viral counterparts.

If you’re developing in C and C++, you know this all too well. It’s easy to allocate a piece of memory and forget to free it later, or accidentally write past the memory buffer. These issues are extremely hard to find without proper tools and often cause sporadic, sudden crashes.

Using sanitizers as you’re building and testing your program can help you catch a great deal of issues in your source code early on, including memory leaks, buffer overflows and undefined behavior.

Today, we’ll be taking a look at three types of Clang sanitizers, how they’re used and what bugs they can help us nip in the bud.

Let’s spray away!

C++20 three way comparison operator: Part 4--Gajendra Gulgulia

The series continue.

C++20 three way comparison operator: Part 4

by Gajendra Gulgulia

From the article:

In the third part of the tutorial series, I uncovered the mechanics of operator <=> and explained in detail, how the compiler re-writes the comparison expression on a custom object with only operator<=> declared as default and how additionally it can make use of synthesized expression to reverse the operands during expression re-writing process. If you haven’t read the third part, I strongly encourage you to read it before reading this tutorial...

C++20 three-way comparison operator: Part 3--Gajendra Gulgulia

The series continue.

C++20 three-way comparison operator: Part 3

by Gajendra Gulgulia

From the article:

In the second part of the tutorial series, I touched upon the rules of the default operator<=> . Unlike default constructors or destructors, the default version of the <=> is not available automatically but has to be declared in the interface of the class and then only it is available to be used.
In this part of the tutorial series, I’ll explain the mechanics of the default operator<=> to further elucidate the rules of the three-way operator, i.e. what exactly is the compiler doing when it sees an expression a < b on a custom object for which no comparison operator is overloaded but only a default version of the operator<=> is declared...

How To Detect Function Overloads in C++17/20, std::from_chars Example--Bartlomiej Filipek

Which way you prefer?

How To Detect Function Overloads in C++17/20, std::from_chars Example

by Bartlomiej Filipek

From the article:

The problem: a library function offers several overloads, but depending on the implementation/compiler, some of the overloads are not available. How to check the existence of an overload? And how to provide a safe fallback?

In this article, I’ll show you a background “theory” and one case - std::from_chars that exposes full support for numbers or only integer support (in GCC, Clang)...

Template Specialization--Rainer Grimm

The series continue.

Template Specialization

by Rainer Grimm

From the article:

Templates define the behavior of families of classes or functions. Often it is required that special types or non-types may be treated special. To support this use case, you can specialize templates.

C++20 three-way comparison operator: Part 2--Gajendra Gulgulia

Simplifying your life.

C++20 three-way comparison operator: Part 2

by Gajendra Gulgulia

From the article:

In the first part of the tutorial series, I laid out the motivation behind C++20’s three way comparison operator: <=> and showcased the simplest use case how it can be useful to remove the boilerplate code for comparison operators : ==, >=, <=, !=, >, < if the semantics of the program requires us to implement them and how they can be gotten rid of by using the defaulted version of three way comparison operator...

Template Argument Deduction of Class Templates--Rainer Grimm

The series continue.

Template Argument Deduction of Class Templates

by Rainer Grimm

From the article:

In my last post Template Arguments, I wrote about function template type deduction (C++98) and auto type deduction (C++11). Today I wear more modern hats. I start with automatic type deduction of non-type template parameters and class templates (C++17) and finish with automatic type deduction of concepts (C++20).