Standard Attributes in C and C++

By Timur Doumler

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 C11, 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 C23, 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.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.