Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
script3r
GitHub Repository: script3r/os161
Path: blob/master/kern/include/cdefs.h
2093 views
1
/*
2
* Copyright (c) 2003, 2006, 2008, 2009
3
* The President and Fellows of Harvard College.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the University nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27
* SUCH DAMAGE.
28
*/
29
30
#ifndef _CDEFS_H_
31
#define _CDEFS_H_
32
33
/*
34
* Some miscellaneous C language definitions and related matters.
35
*/
36
37
38
/*
39
* Build-time assertion. Doesn't generate any code. The error message
40
* on failure is less than ideal, but you can't have everything.
41
*/
42
#define COMPILE_ASSERT(x) ((void)sizeof(struct { unsigned : ((x)?1:-1); }))
43
44
45
/*
46
* Tell GCC how to check printf formats.
47
*/
48
#ifdef __GNUC__
49
#define __PF(a,b) __attribute__((__format__(__printf__, a, b)))
50
#else
51
#define __PF(a,b)
52
#endif
53
54
55
/*
56
* Material for supporting inline functions.
57
*
58
* A function marked inline can be handled by the compiler in three
59
* ways: in addition to possibly inlining into the code for other
60
* functions, the compiler can (1) generate a file-static out-of-line
61
* copy of the function, (2) generate a global out-of-line copy of the
62
* function, or (3) generate no out-of-line copy of the function.
63
*
64
* None of these alone is thoroughly satisfactory. Since an inline
65
* function may or may not be inlined at the compiler's discretion, if
66
* no out-of-line copy exists the build may fail at link time with
67
* undefined symbols. Meanwhile, if the compiler is told to generate a
68
* global out-of-line copy, it will generate one such copy for every
69
* source file where the inline definition is visible; since inline
70
* functions tend to appear in header files, this leads to multiply
71
* defined symbols and build failure. The file-static option isn't
72
* really an improvement, either: one tends to get compiler warnings
73
* about inline functions that haven't been used, which for any
74
* particular source file tends to be at least some of the ones that
75
* have been defined. Furthermore, this method leads to one
76
* out-of-line copy of the inline function per source file that uses
77
* it, which not only wastes space but makes debugging painful.
78
*
79
* Therefore, we use the following scheme.
80
*
81
* In the header file containing the inline functions for the module
82
* "foo", we put
83
*
84
* #ifndef FOO_INLINE
85
* #define FOO_INLINE INLINE
86
* #endif
87
*
88
* where INLINE selects the compiler behavior that does *not* generate
89
* an out-of-line version. Then we define the inline functions
90
* themselves as FOO_INLINE. This allows the compiler to inline the
91
* functions anywhere it sees fit with a minimum of hassles. Then,
92
* when compiling foo.c, before including headers we put
93
*
94
* #define FOO_INLINE // empty
95
*
96
* which causes the inline functions to appear as ordinary function
97
* definitions, not inline at all, when foo.c is compiled. This
98
* ensures that an out-of-line definition appears, and furthermore
99
* ensures that the out-of-line definition is the same as the inline
100
* definition.
101
*
102
* The situation is complicated further because gcc is not compliant
103
* with the C standard. In C99, "inline" means "do not generate an
104
* out-of-line copy" and "extern inline" means "generate a global
105
* out-of-line copy". In gcc, the meanings are reversed. In gcc
106
* versions later than the one OS/161 currently uses, the standard
107
* behavior can be requested; if so, __GNUC_STDC_INLINE__ is defined.
108
* There does not appear to be any way to select this behavior with
109
* gcc 4.1; however, the following definitions should be future-proof.
110
*
111
* (Note that inline functions that appear only within a single source
112
* file can safely be declared "static inline".)
113
*/
114
#if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
115
/* gcc's non-C99 inline semantics */
116
#define INLINE extern inline
117
118
#elif defined(__STDC__) && __STDC_VERSION__ >= 199901L
119
/* C99 */
120
#define INLINE inline
121
122
#else
123
/* something else; static inline is safest */
124
#define INLINE static inline
125
#endif
126
127
128
#endif /* _CDEFS_H_ */
129
130