CLibs
Loading...
Searching...
No Matches
attributes.h File Reference

Function and variable attributes. More...

Go to the source code of this file.

Macros

#define HAS_ATTRIBUTE(TOK)
#define UsageOptional   __attribute__( ( __unused__ ) )
 Stops compiler warnings when the function/variable is unused.
#define PrintfLike(FORMAT_STRING, FIRST_VAR_ARG)
 Tells the compiler which varargs correspond to a format string.
#define ScanfLike(FORMAT_STRING, FIRST_VAR_ARG)
 Tells the compiler which varargs correspond to a format string.
#define UseResult   __attribute__( ( __warn_unused_result__ ) )
 Function's return value must be used.
#define Cold   __attribute__( ( __cold__ ) )
#define Const   __attribute__( ( __const__ ) )
#define BeforeMain   __attribute__( ( constructor ) )
 Function runs before entering main
#define NoReturn   __attribute__( ( noreturn ) )
 Function always exits.
#define Deprecated   __attribute__( ( deprecated ) )
 Function is deprecated and shouldn't be used.
#define Constructor   UseResult
#define Private   static
#define LibraryDefined   static UsageOptional
#define Mathematical   Const
#define NonNullParams(...)

Detailed Description

Function and variable attributes.

Whether the compiler supports attributes (GCC/Clang) or not, this header creates platform-independent macros for certain attributes a function or variable may have.

Some combinations may (definitely will) be missing; this isn't an exhaustive list. (Though all macros are safe to use, no matter the compiler)

Macro Definition Documentation

◆ BeforeMain

#define BeforeMain   __attribute__( ( constructor ) )

Function runs before entering main

◆ Cold

#define Cold   __attribute__( ( __cold__ ) )

◆ Const

#define Const   __attribute__( ( __const__ ) )

Functions return value only depends on its parameters

◆ Constructor

#define Constructor   UseResult

Function allocates memory for an object. Not using function's return value results in a memory leak (or worse).

◆ Deprecated

#define Deprecated   __attribute__( ( deprecated ) )

Function is deprecated and shouldn't be used.

◆ HAS_ATTRIBUTE

#define HAS_ATTRIBUTE ( TOK)
Value:
__has_attribute( TOK )

Evaluates as true if the compiler (clang/GCC) supports the attribute

◆ LibraryDefined

#define LibraryDefined   static UsageOptional

Function or variable is defined in a header file

◆ Mathematical

#define Mathematical   Const

Function has no effect except for the return value. Function's return value only depends on its parameters.

◆ NonNullParams

#define NonNullParams ( ...)
Value:
__attribute( ( nonnull( __VA_ARGS__ ) ) )

Must not be NULL

◆ NoReturn

#define NoReturn   __attribute__( ( noreturn ) )

Function always exits.

◆ PrintfLike

#define PrintfLike ( FORMAT_STRING,
FIRST_VAR_ARG )
Value:
__attribute__( ( __format__( __printf__, FORMAT_STRING, FIRST_VAR_ARG ) ) )

Tells the compiler which varargs correspond to a format string.

◆ Private

#define Private   static

Function or variable is not visible outside the current file

◆ ScanfLike

#define ScanfLike ( FORMAT_STRING,
FIRST_VAR_ARG )
Value:
__attribute__( ( __format__( __scanf__, FORMAT_STRING, FIRST_VAR_ARG ) ) )

Tells the compiler which varargs correspond to a format string.

◆ UsageOptional

#define UsageOptional   __attribute__( ( __unused__ ) )

Stops compiler warnings when the function/variable is unused.

◆ UseResult

#define UseResult   __attribute__( ( __warn_unused_result__ ) )

Function's return value must be used.