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