An attribute adds supplemental information to a C construct. It appears in double square brackets, as in [[maybe_unused]]. Attributes annotate the program’s structure; their particular meaning depends on the attribute. section 2.1
A promise in a function interface
A header can mark a function [[__unsequenced__]]. When application code sees only that header, the compiler can still use the stated property. If the function has no pointer parameters or pointer return, its return value depends only on its argument values. With pointer parameters or returns, possible interference is limited to objects visible through those pointers. section 10.2.3
C23 provides standard attributes for several purposes:
- [[deprecated]] marks a feature as not meant for direct use; using it usually produces a diagnostic. It can take a string explaining why. section 10.2.3
- [[nodiscard]] suggests a warning when a return value is unused. section 10.3
- The standard set also includes fallthrough, maybe_unused, noreturn, reproducible, and unsequenced. Double-underscore variants, such as __unsequenced__, are provided for safer use with macros. 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, ...);
This declaration places a compiler-specific attribute before a function prototype only when __has_c_attribute reports that the attribute is available. section 10.2.3
#ifndef __has_c_attribute # define __has_c_attribute(X) 0 #endif
The fallback definition makes the availability check evaluate to zero when __has_c_attribute itself is unavailable. section 10.2.3
TAKEAWAY: Put useful annotations on interfaces as well as implementations. They can improve diagnostics, safety, security, and performance, but check availability before relying on a compiler-specific attribute. section 10.3 section 10.2.3

























