liveBook · Manning

Prefixed attribute

As explained in Modern C, Third Edition

A prefixed attribute is an implementation-defined attribute whose name combines an implementation prefix, the :: token, and a feature suffix.

A prefixed attribute names an implementation-specific feature with the form prefix::suffix. The prefix is typically associated with a compiler or tool implementor; the suffix identifies the feature. section 10.2.3

A format-checking attribute

[[__gnu__::__format__(__printf__, 3, 4)]] int snprintf(char *buf, size_t size, const char *frmt, ...); This tells GCC or Clang that the function processes a printf-style format at position 3 and begins its variable arguments at position 4, enabling warnings for invalid formats or argument types. section 10.2.3

Apply the feature with these constraints:

  • Pass arguments when supported; syntactically, their parentheses, brackets, and braces must be correctly nested and balanced. section 10.2.3
  • Guard implementation-specific syntax with __has_c_attribute when portability requires testing attribute support. section 10.2.3

How Modern C, Third Edition covers it

How deep it goes
Defines syntax, argument-balance constraints, implementation freedom, and conditional feature testing without detailing compiler internals.
Examples
Uses GNU and Clang format attributes on snprintf and conditional compilation with __has_c_attribute.
What you can do after
Apply it via implementation-specific attribute syntax and guard unsupported features with __has_c_attribute.
How it connects
Connects implementation-specific attributes with standard attributes, compiler diagnostics, preprocessor conditionals, and portability.

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.