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 the assignment of struct value.
120  */
121 #ifdef CC_CONF_ASSIGN_AGGREGATE
122 #define CC_ASSIGN_AGGREGATE(dest, src) CC_CONF_ASSIGN_AGGREGATE(dest, src)
123 #else /* CC_CONF_ASSIGN_AGGREGATE */
124 #define CC_ASSIGN_AGGREGATE(dest, src) *dest = *src
125 #endif /* CC_CONF_ASSIGN_AGGREGATE */
126 
127 #if CC_CONF_NO_VA_ARGS
128 #define CC_NO_VA_ARGS CC_CONF_VA_ARGS
129 #endif
130 
131 /** \def CC_ACCESS_NOW(x)
132  * This macro ensures that the access to a non-volatile variable can
133  * not be reordered or optimized by the compiler.
134  * See also https://lwn.net/Articles/508991/ - In Linux the macro is
135  * called ACCESS_ONCE
136  * The type must be passed, because the typeof-operator is a gcc
137  * extension
138  */
139 
140 #define CC_ACCESS_NOW(type, variable) (*(volatile type *)&(variable))
141 
142 #ifndef NULL
143 #define NULL 0
144 #endif /* NULL */
145 
146 #ifndef MAX
147 #define MAX(n, m) (((n) < (m)) ? (m) : (n))
148 #endif
149 
150 #ifndef MIN
151 #define MIN(n, m) (((n) < (m)) ? (n) : (m))
152 #endif
153 
154 #ifndef ABS
155 #define ABS(n) (((n) < 0) ? -(n) : (n))
156 #endif
157 
158 
159 #define CC_CONCAT2(s1, s2) s1##s2
160 /**
161  * A C preprocessing macro for concatenating two preprocessor tokens.
162  *
163  * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow
164  * concatenation of two \#defined macros.
165  */
166 #define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2)
167 #define CC_CONCAT_EXT_2(s1, s2) CC_CONCAT2(s1, s2)
168 
169 /**
170  * A C preprocessing macro for concatenating three preprocessor tokens.
171  */
172 #define CC_CONCAT3(s1, s2, s3) s1##s2##s3
173 #define CC_CONCAT_EXT_3(s1, s2, s3) CC_CONCAT3(s1, s2, s3)
174 
175 #endif /* CC_H_ */