Contiki-NG
cc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003, Adam Dunkels.
3  * All rights reserved.
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
11  * copyright notice, this list of conditions and the following
12  * disclaimer in the documentation and/or other materials provided
13  * with the distribution.
14  * 3. The name of the author may not be used to endorse or promote
15  * products derived from this software without specific prior
16  * written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * This file is part of the Contiki desktop OS
31  *
32  *
33  */
34 
35 /**
36  * \file
37  * Default definitions of C compiler quirk work-arounds.
38  * \author Adam Dunkels <adam@dunkels.com>
39  *
40  * This file is used for making use of extra functionality of some C
41  * compilers used for Contiki, and defining work-arounds for various
42  * quirks and problems with some other C compilers.
43  */
44 
45 #ifndef CC_H_
46 #define CC_H_
47 
48 #include "contiki.h"
49 #include "sys/cc-gcc.h"
50 
51 /**
52  * Configure if the C compiler supports the "register" keyword for
53  * function arguments.
54  */
55 #if CC_CONF_REGISTER_ARGS
56 #define CC_REGISTER_ARG register
57 #else /* CC_CONF_REGISTER_ARGS */
58 #define CC_REGISTER_ARG
59 #endif /* CC_CONF_REGISTER_ARGS */
60 
61 /**
62  * Configure if the C compiler supports the arguments for function
63  * pointers.
64  */
65 #if CC_CONF_FUNCTION_POINTER_ARGS
66 #define CC_FUNCTION_POINTER_ARGS 1
67 #else /* CC_CONF_FUNCTION_POINTER_ARGS */
68 #define CC_FUNCTION_POINTER_ARGS 0
69 #endif /* CC_CONF_FUNCTION_POINTER_ARGS */
70 
71 /**
72  * Configure if the C compiler have problems with const function pointers
73  */
74 #ifdef CC_CONF_CONST_FUNCTION_BUG
75 #define CC_CONST_FUNCTION
76 #else /* CC_CONF_CONST_FUNCTION_BUG */
77 #define CC_CONST_FUNCTION const
78 #endif /* CC_CONF_CONST_FUNCTION_BUG */
79 
80 /**
81  * Configure work-around for unsigned char bugs with sdcc.
82  */
83 #if CC_CONF_UNSIGNED_CHAR_BUGS
84 #define CC_UNSIGNED_CHAR_BUGS 1
85 #else /* CC_CONF_UNSIGNED_CHAR_BUGS */
86 #define CC_UNSIGNED_CHAR_BUGS 0
87 #endif /* CC_CONF_UNSIGNED_CHAR_BUGS */
88 
89 /**
90  * Configure if C compiler supports double hash marks in C macros.
91  */
92 #if CC_CONF_DOUBLE_HASH
93 #define CC_DOUBLE_HASH 1
94 #else /* CC_CONF_DOUBLE_HASH */
95 #define CC_DOUBLE_HASH 0
96 #endif /* CC_CONF_DOUBLE_HASH */
97 
98 #ifdef CC_CONF_INLINE
99 #define CC_INLINE CC_CONF_INLINE
100 #else /* CC_CONF_INLINE */
101 #define CC_INLINE
102 #endif /* CC_CONF_INLINE */
103 
104 #ifdef CC_CONF_ALIGN
105 #define CC_ALIGN(n) CC_CONF_ALIGN(n)
106 #endif /* CC_CONF_INLINE */
107 
108 /**
109  * Configure if the C compiler supports functions that are not meant to return
110  * e.g. with __attribute__((__noreturn__))
111  */
112 #ifdef CC_CONF_NORETURN
113 #define CC_NORETURN CC_CONF_NORETURN
114 #else
115 #define CC_NORETURN
116 #endif /* CC_CONF_NORETURN */
117 
118 /**
119  * Configure if the C compiler supports marking functions as deprecated
120  * e.g. with __attribute__((deprecated))
121  */
122 #ifdef CC_CONF_DEPRECATED
123 #define CC_DEPRECATED(msg) CC_CONF_DEPRECATED(msg)
124 #else
125 #define CC_DEPRECATED(msg)
126 #endif /* CC_CONF_DEPRECATED */
127 
128 /**
129  * Configure if the C compiler supports the assignment of struct value.
130  */
131 #ifdef CC_CONF_ASSIGN_AGGREGATE
132 #define CC_ASSIGN_AGGREGATE(dest, src) CC_CONF_ASSIGN_AGGREGATE(dest, src)
133 #else /* CC_CONF_ASSIGN_AGGREGATE */
134 #define CC_ASSIGN_AGGREGATE(dest, src) *dest = *src
135 #endif /* CC_CONF_ASSIGN_AGGREGATE */
136 
137 #if CC_CONF_NO_VA_ARGS
138 #define CC_NO_VA_ARGS CC_CONF_VA_ARGS
139 #endif
140 
141 /** \def CC_ACCESS_NOW(x)
142  * This macro ensures that the access to a non-volatile variable can
143  * not be reordered or optimized by the compiler.
144  * See also https://lwn.net/Articles/508991/ - In Linux the macro is
145  * called ACCESS_ONCE
146  * The type must be passed, because the typeof-operator is a gcc
147  * extension
148  */
149 
150 #define CC_ACCESS_NOW(type, variable) (*(volatile type *)&(variable))
151 
152 #ifndef NULL
153 #define NULL 0
154 #endif /* NULL */
155 
156 #ifndef MAX
157 #define MAX(n, m) (((n) < (m)) ? (m) : (n))
158 #endif
159 
160 #ifndef MIN
161 #define MIN(n, m) (((n) < (m)) ? (n) : (m))
162 #endif
163 
164 #ifndef ABS
165 #define ABS(n) (((n) < 0) ? -(n) : (n))
166 #endif
167 
168 
169 #define CC_CONCAT2(s1, s2) s1##s2
170 /**
171  * A C preprocessing macro for concatenating two preprocessor tokens.
172  *
173  * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow
174  * concatenation of two \#defined macros.
175  */
176 #define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2)
177 #define CC_CONCAT_EXT_2(s1, s2) CC_CONCAT2(s1, s2)
178 
179 /**
180  * A C preprocessing macro for concatenating three preprocessor tokens.
181  */
182 #define CC_CONCAT3(s1, s2, s3) s1##s2##s3
183 #define CC_CONCAT_EXT_3(s1, s2, s3) CC_CONCAT3(s1, s2, s3)
184 
185 #endif /* CC_H_ */