No more plain old data

When working in C++, you often hear about POD types (which stands for Plain Old Data). PODs are useful for communicating with code written in other programming languages (such as C or .NET languages). They can also be copied using memcpy (which is important because this is a fast, low-level function that provides performance benefits), and have other characteristics that are key for some scenarios. However, the new C++20 standard has deprecated the concept of POD types in favor of two more refined categories, which are trivial and standard-layout types. In this post, I will discuss what these categories are and when to use instead of POD.

A C++20 coroutine example

One of the most important new features in the C++20 is coroutines. A coroutine is a function that has the ability to be suspended and resumed. A function becomes a coroutine if it uses any of the following:

  • the co_await operator to suspend execution until resumed
  • the co_return keyword to complete execution and optionally return a value
  • the co_yield keyword to suspend execution and return a value

A coroutine must also have a return type that satisfies some requirements. However, the C++20 standard, only defines a framework for the execution of coroutines, but does not define any coroutine types satisfying such requirements. That means, we need to either write our own or rely on 3rd party libraries for this. In this post, I’ll show how to write some simple examples using the cppcoro library.

Highlights from Microsoft Build 2020

The Microsoft Build 2020 event happened this week, and, unlike all previous editions, it was a digital event only. Moreover, it was also free, so everybody could attend the 48 hours marathon. Microsoft made a lot of announcements and released various products and services for Windows, Azure, Office, Visual Studio, Edge, and more. In this post, I will summarize the things that I found the most interesting for me.

Modules in Clang 11

In my previous post, I wrote about the support for C++20 modules in Visual Studio 2019 16.5. VC++ is not the only major compiler that has experimental support for modules. Clang has its own implementation, although only partial. In this post, I will discuss the support available in Clang 11. You can check the current status here.

Modules in VC++ 2019 16.5

Modules are one of the bigest changes in C++20 but the compilers’ support for them is a work in progress. The Visual C++ compiler has experimental support for modules that can be enabled by using the /experimental:module and /std:c++latest switches. In this post, I will walk through the core of the functionality available in Visual…

My book “Learn C# Programming” has been published

I am pleased to announce that my new book, Learn C# Programming, that I co-authored together with Raffaele Rialdi (Microsoft MVP/speaker) and Ankit Sharma (C# Corner MVP/Google Dev Expert/speaker) has been published at PacktPub. The book can be ordered at PacktPub and Amazon (ISBN 9781789805864).

This book is primarily intended for people that want to learn to program in C# for .NET. This book will not teach you the basics of programming but it will teach you the C# language from the very basics to the most advanced topics, and to the latest in C# 8, which is the current version of the language. However, if you are an experienced C# programmer, but want to learn the latest features from C# 8 or how to work with .NET Core, target multiple platforms, and migrate from .NET Framework, this book should be handy for you too.

C++20 atomic_ref

C++11 provides the atomic operations library that features classes and functions that enable us to perform atomic operations using lock-free mechanisms. There are primarily two class templates in this library, std::atomic and std::atomic_flag. The latter, which defines an atomic boolean type, is guaranteed to always be lock-free and is implemented using the lock-free atomic CPU instructions. The former however, may actually be implemented using mutexes or other locking operations. In this article, we will look at a new class template, introduced in C++20, std::atomic_ref.

C++20 designated initializers

The C++20 standard provides new ways to initialize aggregates. These are:

  • list initialization with designated initializers, that has the following forms:
    T object = { .designator = arg1 , .designator { arg2 } ... };
    T object { .designator = arg1 , .designator { arg2 } ... };
  • direct initialization, that has the following form:
    T object (arg1, arg2, ...);

In this article, we will see how list initialization with designated initializers work.