]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/cc.h
xnu-6153.61.1.tar.gz
[apple/xnu.git] / bsd / net / cc.h
1 /*
2 * Copyright (c) 2017 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 2003, Adam Dunkels.
30 * All rights reserved.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above
38 * copyright notice, this list of conditions and the following
39 * disclaimer in the documentation and/or other materials provided
40 * with the distribution.
41 * 3. The name of the author may not be used to endorse or promote
42 * products derived from this software without specific prior
43 * written permission.
44 *
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
46 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
49 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
51 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
53 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
54 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
55 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 *
57 * This file is part of the Contiki desktop OS
58 *
59 *
60 */
61
62 /**
63 * \file
64 * Default definitions of C compiler quirk work-arounds.
65 * \author Adam Dunkels <adam@dunkels.com>
66 *
67 * This file is used for making use of extra functionality of some C
68 * compilers used for Contiki, and defining work-arounds for various
69 * quirks and problems with some other C compilers.
70 */
71
72 #ifndef CC_H_
73 #define CC_H_
74
75 #include "contiki-conf.h"
76
77 /**
78 * Configure if the C compiler supports the "register" keyword for
79 * function arguments.
80 */
81 #if CC_CONF_REGISTER_ARGS
82 #define CC_REGISTER_ARG register
83 #else /* CC_CONF_REGISTER_ARGS */
84 #define CC_REGISTER_ARG
85 #endif /* CC_CONF_REGISTER_ARGS */
86
87 /**
88 * Configure if the C compiler supports the arguments for function
89 * pointers.
90 */
91 #if CC_CONF_FUNCTION_POINTER_ARGS
92 #define CC_FUNCTION_POINTER_ARGS 1
93 #else /* CC_CONF_FUNCTION_POINTER_ARGS */
94 #define CC_FUNCTION_POINTER_ARGS 0
95 #endif /* CC_CONF_FUNCTION_POINTER_ARGS */
96
97 /**
98 * Configure if the C compiler supports fastcall function
99 * declarations.
100 */
101 #ifdef CC_CONF_FASTCALL
102 #define CC_FASTCALL CC_CONF_FASTCALL
103 #else /* CC_CONF_FASTCALL */
104 #define CC_FASTCALL
105 #endif /* CC_CONF_FASTCALL */
106
107 /**
108 * Configure if the C compiler have problems with const function pointers
109 */
110 #ifdef CC_CONF_CONST_FUNCTION_BUG
111 #define CC_CONST_FUNCTION
112 #else /* CC_CONF_FASTCALL */
113 #define CC_CONST_FUNCTION const
114 #endif /* CC_CONF_FASTCALL */
115
116 /**
117 * Configure work-around for unsigned char bugs with sdcc.
118 */
119 #if CC_CONF_UNSIGNED_CHAR_BUGS
120 #define CC_UNSIGNED_CHAR_BUGS 1
121 #else /* CC_CONF_UNSIGNED_CHAR_BUGS */
122 #define CC_UNSIGNED_CHAR_BUGS 0
123 #endif /* CC_CONF_UNSIGNED_CHAR_BUGS */
124
125 /**
126 * Configure if C compiler supports double hash marks in C macros.
127 */
128 #if CC_CONF_DOUBLE_HASH
129 #define CC_DOUBLE_HASH 1
130 #else /* CC_CONF_DOUBLE_HASH */
131 #define CC_DOUBLE_HASH 0
132 #endif /* CC_CONF_DOUBLE_HASH */
133
134 #ifdef CC_CONF_INLINE
135 #define CC_INLINE CC_CONF_INLINE
136 #else /* CC_CONF_INLINE */
137 #define CC_INLINE
138 #endif /* CC_CONF_INLINE */
139
140 /**
141 * Configure if the C compiler supports the assignment of struct value.
142 */
143 #ifdef CC_CONF_ASSIGN_AGGREGATE
144 #define CC_ASSIGN_AGGREGATE(dest, src) CC_CONF_ASSIGN_AGGREGATE(dest, src)
145 #else /* CC_CONF_ASSIGN_AGGREGATE */
146 #define CC_ASSIGN_AGGREGATE(dest, src) *dest = *src
147 #endif /* CC_CONF_ASSIGN_AGGREGATE */
148
149 #if CC_CONF_NO_VA_ARGS
150 #define CC_NO_VA_ARGS CC_CONF_VA_ARGS
151 #endif
152
153 #ifndef NULL
154 #define NULL 0
155 #endif /* NULL */
156
157 #ifndef MAX
158 #define MAX(n, m) (((n) < (m)) ? (m) : (n))
159 #endif
160
161 #ifndef MIN
162 #define MIN(n, m) (((n) < (m)) ? (n) : (m))
163 #endif
164
165 #ifndef ABS
166 #define ABS(n) (((n) < 0) ? -(n) : (n))
167 #endif
168
169
170 #define CC_CONCAT2(s1, s2) s1##s2
171 /**
172 * A C preprocessing macro for concatenating two preprocessor tokens.
173 *
174 * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow
175 * concatenation of two \#defined macros.
176 */
177 #define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2)
178 #define CC_CONCAT_EXT_2(s1, s2) CC_CONCAT2(s1, s2)
179
180 /**
181 * A C preprocessing macro for concatenating three preprocessor tokens.
182 */
183 #define CC_CONCAT3(s1, s2, s3) s1##s2##s3
184 #define CC_CONCAT_EXT_3(s1, s2, s3) CC_CONCAT3(s1, s2, s3)
185
186 #endif /* CC_H_ */