aboutsummaryrefslogtreecommitdiff
path: root/arch/all/core/include/cdefs/attrs.h
blob: 8b41e1b7835c010011cfdca3633d4ef16d8699e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* ****************************************************************************
 * cdefs/attrs.h -- C Compiler helpers.
 *
 * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
 *
 * This file is part of the 'all/core' module in libcarrot, an experimental
 * modular libc project.
 *
 * This file is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This file is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Lesser Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this file. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************* */
#ifndef  _CDEFS_H
# error "This file should be included by `cdefs.h`!"
#endif
#include <cdefs/features.h>

/* ************************************************************************* */
/*  __THROW: optimize function calls for C++                                 */
/* ************************************************************************* */
/* <TODO: explanation> */

#if __USE_CXX98
# define __THROW throw()
#elif defined(__nothrow)
# define __THROW __nothrow
#else
# define __THROW
#endif
/* ************************************************************************* */
/*  __inline: force inlining                                                 */
/* ************************************************************************* */
/* The `inline` function attribute is simply an indication; this attribute
 * forces the inlining of a function. */

#ifndef  __inline
# define __inline /* __inline: not implemented */
#endif
/* ************************************************************************* */
/*  __asm_inline: force inlining for assembly functions                      */
/* ************************************************************************* */
/* This attribute forces inlining and enables optimizations suitable for
 * inline assembly functions/macros such as the ones defined in `machine.h`. */

#ifndef  __unroll_loops
# define __unroll_loops /* __unroll_loops: not implemented */
#endif

#ifdef  __asm_inline
# undef __asm_inline
#endif
#define __asm_inline __unroll_loops __inline
/* ************************************************************************* */
/*  __pure: no side effects                                                  */
/* ************************************************************************* */
/* For a set of arguments, there is a constant (cacheable) result, and
 * calculating it doesn't require any side effect. */

#ifndef  __pure
# define __pure /* __pure: not implemented */
#endif
/* ************************************************************************* */
/*  __atleast, __notnull: static check for elements in an array              */
/* ************************************************************************* */
/* This feature appeared in C99. It basically checks that an array contains
 * at least _N elements. It can be used as a cross-compiler way to check that
 * a pointer is not NULL.
 *
 * It only works for types that we know the size of. It won't with `void`
 * pointers or anonymous structures (such as `FILE` or `DIR` in the public
 * API). */

#ifdef  __atleast
# undef __atleast
#endif
#ifdef  __notnull
# undef __notnull
#endif
#if __USE_C99
# define __atleast(_N) static (_N)
#else
# define __atleast(_N)
#endif
#define __notnull __atleast(1)
/* ************************************************************************* */
/*  __nonnull: a function requires a pointer argument not to be NULL         */
/* ************************************************************************* */
/* A warning shall be issued when a NULL value is passed as an argument that
 * shouldn't be. The macro argument is the argument index, starting from 1. */

#ifndef  __nonnull
# define __nonnull(_I, _N) /* __nonnull: not implemented */
#endif
/* ************************************************************************* */
/*  __wur: warn unused result                                                */
/* ************************************************************************* */
/* A warning shall be issued if the result of the function isn't used.
 * Note that __pure implies __wur, you don't need to put the two. */

#ifndef  __wur
# define __wur /* __wur: not implemented */
#endif
/* ************************************************************************* */
/*  __restrict: portable 'restrict' keyword                                  */
/* ************************************************************************* */
/* Uses 'restrict' if we're in >=C99, or nothing if not. */

#ifdef  __restrict
# undef __restrict
#endif
#if __USE_C99
# define __restrict restrict
#else
# define __restrict
#endif
/* ************************************************************************* */
/*  __malloc: is a memory allocation function                                */
/* ************************************************************************* */
/* TODO: why is this attribute useful? */

#ifndef  __malloc
# define __malloc /* __malloc: not implemented */
#endif
/* ************************************************************************* */
/*  __printf_format: is a function expecting a printf-like format            */
/* ************************************************************************* */
/* This produces the damn right warnings for when you don't use the standard
 * functionnalities of `printf` correctly. */

#ifndef  __printf_format
# define __printf_format(_FI, _AI) /* __printf_format: not implemented */
#endif
/* ************************************************************************* */
/*  __deprecated: a function, structure or structure member is deprecated    */
/* ************************************************************************* */
/* You really shouldn't use what's marked with that argument, it might
 * disappear at any time. */

#ifndef  __deprecated
# define __deprecated /* __deprecated: not implemented */
#endif
/* ************************************************************************* */
/*  __noreturn: this is the point of.                                        */
/* ************************************************************************* */
/* Use this when you know you'll abort or exit or whatever. */

#ifndef  __noreturn
# define __noreturn
#endif