Lecture: Standard Attributes in C and C++

This talk is an in-depth tour of the standard attributes currently available in the C and C++ programming languages.

Some attributes such as deprecated, fallthrough, nodiscard, and maybe_unused are very helpful to produce or suppress warnings. Others, such as likely and unlikely, can be used as optimisation hints to the compiler, although it can be difficult to avoid misuse and accidentally pessimise your code instead. The attributes noreturn and assume can even inject undefined behaviour into your code. And then there is no_unique_address, which can be used to optimise the class layout, but comes with its own caveats regarding portability across major compilers.

C++ has had standard attributes since C++11, and every new standard is adding more. The C language introduced attributes in C23, adopted many attributes from C++, and added two new attributes exclusive to C: unsequenced and reproducible.

In this talk, we will describe the syntax and semantics of all existing standard attributes, including the latest additions in C23 and C++23, discuss the use cases for each one, show practical code examples, and offer guidelines on how to use them safely and effectively. We will also talk about the often-misunderstood C++ language design rule that attributes are "ignorable" and what that actually means.


Day: 2023-04-19
Start time: 14:00
Duration: 01:30
Room: Bristol I
Track: Modern C++



Click here to let us know how you liked this event.

Concurrent Events