liveBook · Manning

Double-underscore attribute form

As explained in Modern C, Third Edition

A double-underscore attribute form is an attribute spelling whose identifier is prefixed and postfixed with double underscores to avoid collisions with application-defined macros.

A double-underscore attribute form is a macro-safer spelling for an attribute: its identifier uses double underscores, as in __unsequenced__. C23 provides these variants alongside standard spellings such as [[unsequenced]], [[deprecated]], and [[nodiscard]]. section 10.2.3

Macro-safe attribute spellings

The standard attribute [[unsequenced]] has the macro-safer form __unsequenced__. Related attribute names include __deprecated__, __fallthrough__, __maybe_unused__, __nodiscard__, __noreturn__, and __reproducible__. section 10.2.3

#if __has_c_attribute(__gnu__::__format__)
  [[__gnu__::__format__(__printf__, 3, 4)]]
#endif
  int snprintf(char *buf, size_t size, const char *frmt, ...);

Shows double-underscore names in a GNU-namespaced attribute and in its attribute arguments. section 10.2.3

How Modern C, Third Edition covers it

How deep it goes
Defines C23 macro-safer variants and lists examples, but does not explain their implementation mechanics.
Examples
Uses __unsequenced__, [[deprecated]], [[nodiscard]], and a __gnu__::__format__ declaration.
What you can do after
Evaluate/understand macro-safer attribute spellings and recognize their standard counterparts.
How it connects
Connects attribute spelling with C23, standard attributes, macros, and GNU attribute namespaces.

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.