liveBook · Manning

Standard attribute

As explained in Modern C, Third Edition

A standard attribute is an attribute defined by the C standard with a specified meaning and syntax.

A standard attribute is a C-standard annotation written with double brackets, such as [[deprecated]] or [[nodiscard]]. It attaches a specified meaning to a language feature, allowing implementations to diagnose misuse or apply defined semantic assumptions. section 10.2.3

Deprecation annotation

[[deprecated("tell all about it")]] int old_interface(void); Using old_interface normally causes a compiler diagnostic. The diagnostic is not required when the use occurs inside another deprecated feature. [[nodiscard]] is another standard attribute that may receive a string argument. section 10.2.3

C23 supplies standard attributes including:

  • [[deprecated]], [[fallthrough]], [[maybe_unused]], [[nodiscard]], [[noreturn]], [[unsequenced]], and [[reproducible]]. section 10.2.3
  • Double-underscore variants such as [[__unsequenced__]] provide macro-safer spellings. section 10.2.3

How Modern C, Third Edition covers it

How deep it goes
Defines syntax, lists C23 attributes, and explains deprecated, fallthrough, and unsequenced behavior without covering every attribute in detail.
Examples
Shows [[deprecated("tell all about it")]], [[__unsequenced__]], and annotations applied to functions and switch control flow.
What it assumes
Assumes familiarity with C functions, headers, compiler diagnostics, and switch statements.
What you can do after
Evaluate/understand standard attribute syntax, diagnostic effects, and macro-safer spellings.
How it connects
Connects attributes with compiler diagnostics, switch fallthrough, pure functions, pointer interference, and the C memory model.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.