CLibs
Loading...
Searching...
No Matches
attributes.h
Go to the documentation of this file.
1
13
14// Created by MacBook on 10.01.2025.
15
16#ifndef CLIBS_ATTRIBUTES_H
17#define CLIBS_ATTRIBUTES_H
18
19
20#ifdef __has_attribute
22#define HAS_ATTRIBUTE( TOK ) __has_attribute( TOK )
23#else // ndef __has_attribute
25#define HAS_ATTRIBUTE( TOK ) 0
26#endif // __has_attribute
27
28
29#if HAS_ATTRIBUTE( unused )
31#define UsageOptional __attribute__( ( __unused__ ) )
32#else // unused
33#define UsageOptional
34#endif // unused
35
36
37#if HAS_ATTRIBUTE( format )
39#define PrintfLike( FORMAT_STRING, FIRST_VAR_ARG ) \
40 __attribute__( ( __format__( __printf__, FORMAT_STRING, FIRST_VAR_ARG ) ) )
41
42#define ScanfLike( FORMAT_STRING, FIRST_VAR_ARG ) \
43 __attribute__( ( __format__( __scanf__, FORMAT_STRING, FIRST_VAR_ARG ) ) )
44#else // format
45#define PrintfLike( FORMAT_STRING, FIRST_VAR_ARG )
46#define ScanfLike( FORMAT_STRING, FIRST_VAR_ARG )
47#endif // format
48
49
50#if HAS_ATTRIBUTE( warn_unused_result )
52#define UseResult __attribute__( ( __warn_unused_result__ ) )
53#else // warn_unused_result
54#define UseResult
55#endif // warn_unused_result
56
57
58#if HAS_ATTRIBUTE( cold )
59#define Cold __attribute__( ( __cold__ ) )
60#else // cold
61#define Cold
62#endif // cold
63
64
65#if HAS_ATTRIBUTE( const )
67#define Const __attribute__( ( __const__ ) )
68#else // const
69#define Const
70#endif // const
71
72
73#if HAS_ATTRIBUTE( constructor )
75#define BeforeMain __attribute__( ( constructor ) )
76#else
77#define BeforeMain UsageOptional
78#endif // constructor
79
80
81#if HAS_ATTRIBUTE( noreturn )
83#define NoReturn __attribute__( ( noreturn ) )
84#else
85#define NoReturn
86#endif // constructor
87
88
89#if HAS_ATTRIBUTE( deprecated )
91#define Deprecated __attribute__( ( deprecated ) )
92#else
93#define Deprecated
94#endif
95
96
101#define Constructor UseResult
102
104#define Private static
105
107#define LibraryDefined static UsageOptional
108
113#define Mathematical Const
114
115
116#if HAS_ATTRIBUTE( nonnull )
118#define NonNullParams( ... ) __attribute( ( nonnull( __VA_ARGS__ ) ) )
119#else
120#define NonNullParams
121#endif
122
123
124#endif //CLIBS_ATTRIBUTES_H