Attributes

Overview

Attributes are a new syntactic construct introduced in C23. Delimited with [[...]], they specify additional information for various source constructs.

The __has_c_attribute can be used in preprocessor conditionals to test for presence of an attribute.

Standard Attributes

Standard attributes have an equivalent form with leading and trailing double underscores. Generally these should be preferred to avoid application-defined macros from interfering with them.

deprecated

The [[deprecated]] attribute marks names and entities whose use is still allowed, but is discouraged for some reason.

fallthrough

The [[fallthrough]] attribute is intended to suppress diagnostics that an implementation may otherwise issue for a case or default label reachable from another case or default label.

maybe_unused

The [[maybe_unused]] attribute indicates that a name or entity is possibly intentionally unused.

nodiscard

The [[nodiscard]] attribute indicates the return value of a function should not be evaluated to a void expression. This can be suppressed only if explicitly casting to void.

noreturn

The [[noreturn]] attribute should produce diagnostics for attributed functions that appear capable of returning to its caller.

Prefixed Attributes

Alongside the standard attributes are the prefixed attributes. They have form prefix::suffix, where prefix is an identifier chosen by some vendor (e.g. clang).

Powered by Forestry.md