Common GCC Attributes

Function attributes fallthrough The fallthrough attribute with a null statement serves as a fallthrough statement. It hints to the compiler that a statement that falls through to another case label, or user-defined label in a switch statement is intentional and thus the -Wimplicit-fallthrough warning must not trigger. For compatibility with GCC and Clang you can also use // fall through or // fallthrough. switch(cond) { case 1: bar(1); __attribute__((fallthrough)); case 2: … } deprecated & deprecated (msg) The deprecated attribute results in a warning if the function is used anywhere in the source file. This is useful when identifying functions that are expected to be removed in a future version of a program. The warning also includes the location of the declaration of the deprecated function, to enable users to easily find further information about why the function is deprecated, or what they should do instead. ...

13 August 2024 · 4 min