compiler_port.h
Go to the documentation of this file.
1 /**
2  * @file compiler_port.h
3  * @brief Compiler specific definitions
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 Oryx Embedded SARL. All rights reserved.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 2.6.0
27  **/
28 
29 #ifndef _COMPILER_PORT_H
30 #define _COMPILER_PORT_H
31 
32 //Dependencies
33 #include <stddef.h>
34 #include <stdint.h>
35 #include <inttypes.h>
36 
37 //ARM compiler V6?
38 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
39  #include <stdarg.h>
40 #endif
41 
42 //C++ guard
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 //TI C2000-CGT compiler?
48 #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
49  typedef char char_t;
50  typedef int32_t int_t;
51  typedef uint32_t uint_t;
52  typedef int16_t int8_t;
53  typedef uint16_t uint8_t;
54 #else
55  typedef char char_t;
56  typedef signed int int_t;
57  typedef unsigned int uint_t;
58 #endif
59 
60 #if defined(__ADSPSC5xx__)
61  typedef uint8_t bool_t;
62 #elif !defined(R_TYPEDEFS_H) && !defined(USE_CHIBIOS_2)
63  typedef int bool_t;
64 #endif
65 
66 //ARM compiler?
67 #if defined(__CC_ARM)
68  #undef PRIu8
69  #undef PRIu16
70  #define PRIu8 "u"
71  #define PRIu16 "u"
72  #define PRIuSIZE "u"
73  #define PRIXSIZE "X"
74  #define PRIuTIME "lu"
75 //Microchip XC32 compiler?
76 #elif defined(__XC32)
77  #if defined(__C32_LEGACY_LIBC__)
78  #define PRIuSIZE "lu"
79  #define PRIXSIZE "lX"
80  #define PRIuTIME "lu"
81  #else
82  #define PRIuSIZE "u"
83  #define PRIXSIZE "X"
84  #define PRIuTIME "u"
85  #endif
86 //NXP MCUXpresso compiler?
87 #elif defined(__MCUXPRESSO)
88  #undef PRIu64
89  #define PRIu64 "llu"
90  #define PRIuSIZE "u"
91  #define PRIXSIZE "X"
92  #define PRIuTIME "lu"
93 //NXP CodeWarrior compiler?
94 #elif defined(__CWCC__)
95  #define PRIu8 "u"
96  #define PRIu16 "u"
97  #define PRIu32 "u"
98  #define PRIx8 "x"
99  #define PRIx16 "x"
100  #define PRIx32 "x"
101  #define PRIX8 "X"
102  #define PRIX16 "X"
103  #define PRIX32 "X"
104  #define PRIuSIZE "u"
105  #define PRIXSIZE "X"
106  #define PRIuTIME "u"
107 //Espressif ESP-IDF compiler?
108 #elif defined(IDF_VER)
109  #undef PRIu8
110  #undef PRIu16
111  #undef PRIx8
112  #undef PRIx16
113  #undef PRIX8
114  #undef PRIX16
115  #define PRIu8 "u"
116  #define PRIu16 "u"
117  #define PRIx8 "x"
118  #define PRIx16 "x"
119  #define PRIX8 "X"
120  #define PRIX16 "X"
121  #define PRIuSIZE "u"
122  #define PRIXSIZE "X"
123  #define PRIuTIME "lu"
124 //TI C2000-CGT compiler?
125 #elif defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__)
126  #undef PRIu8
127  #undef PRIX8
128  #define PRIu8 PRIu16
129  #define PRIX8 PRIX16
130  #define PRIuSIZE "u"
131  #define PRIXSIZE "X"
132  #define PRIuTIME "lu"
133 //Linux/FreeBSD GCC compiler
134 #elif defined(__linux__) || defined(__FreeBSD__)
135  #define PRIuSIZE "zu"
136  #define PRIXSIZE "zX"
137  #define PRIuTIME "lu"
138 //Win32 compiler?
139 #elif defined(_WIN32)
140  #define PRIuSIZE "Iu"
141  #define PRIXSIZE "IX"
142  #define PRIuTIME "lu"
143 //GCC compiler (with newlib-nano runtime library)?
144 #elif defined(__GNUC__) && defined(_NANO_FORMATTED_IO) && (_NANO_FORMATTED_IO != 0)
145  #undef PRIu8
146  #undef PRIu16
147  #undef PRIx8
148  #undef PRIx16
149  #undef PRIX8
150  #undef PRIX16
151  #define PRIu8 "u"
152  #define PRIu16 "u"
153  #define PRIx8 "x"
154  #define PRIx16 "x"
155  #define PRIX8 "X"
156  #define PRIX16 "X"
157  #define PRIuSIZE "u"
158  #define PRIXSIZE "X"
159  #define PRIuTIME "u"
160 //GCC compiler (with newlib-standard runtime library)?
161 #else
162  #define PRIuSIZE "u"
163  #define PRIXSIZE "X"
164  #define PRIuTIME "lu"
165 #endif
166 
167 //ARM compiler V6?
168 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
169  int vsnprintf(char *dest, size_t size, const char *format, va_list ap);
170  char *strtok_r(char *s, const char *delim, char **last);
171 //GCC compiler (for PowerPC architecture)?
172 #elif defined(__GNUC__) && defined(__PPC_EABI__)
173  typedef uint32_t time_t;
174  int strcasecmp(const char *s1, const char *s2);
175  int strncasecmp(const char *s1, const char *s2, size_t n);
176  char *strtok_r(char *s, const char *delim, char **last);
177 //GCC compiler?
178 #elif defined(__GNUC__)
179  int strcasecmp(const char *s1, const char *s2);
180  int strncasecmp(const char *s1, const char *s2, size_t n);
181  char *strtok_r(char *s, const char *delim, char **last);
182 //Tasking compiler?
183 #elif defined(__TASKING__)
184  char *strtok_r(char *s, const char *delim, char **last);
185 //Microchip XC32 compiler?
186 #elif defined(__XC32)
187  #define sprintf _sprintf
188  int sprintf(char *str, const char *format, ...);
189  int strcasecmp(const char *s1, const char *s2);
190  int strncasecmp(const char *s1, const char *s2, size_t n);
191  char *strtok_r(char *s, const char *delim, char **last);
192 //NXP CodeWarrior compiler?
193 #elif defined(__CWCC__)
194  typedef uint32_t time_t;
195  int strcasecmp(const char *s1, const char *s2);
196  int strncasecmp(const char *s1, const char *s2, size_t n);
197  char *strtok_r(char *s, const char *delim, char **last);
198 //Renesas CC-RX compiler?
199 #elif defined(__CCRX__)
200  int strcasecmp(const char *s1, const char *s2);
201  int strncasecmp(const char *s1, const char *s2, size_t n);
202  char *strtok_r(char *s, const char *delim, char **last);
203 //TI CGT compiler?
204 #elif defined(__TI_COMPILER_VERSION__)
205  int strcasecmp(const char *s1, const char *s2);
206  int strncasecmp(const char *s1, const char *s2, size_t n);
207  char *strtok_r(char *s, const char *delim, char **last);
208 #endif
209 
210 //ARM compiler V6?
211 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
212  #undef __packed_struct
213  #define __packed_struct struct __attribute__((packed))
214  #undef __packed_union
215  #define __packed_union union __attribute__((packed))
216 //GCC compiler?
217 #elif defined(__GNUC__)
218  #undef __packed_struct
219  #define __packed_struct struct __attribute__((__packed__))
220  #undef __packed_union
221  #define __packed_union union __attribute__((__packed__))
222 //ARM compiler?
223 #elif defined(__CC_ARM)
224  #pragma anon_unions
225  #undef __packed_struct
226  #define __packed_struct __packed struct
227  #undef __packed_union
228  #define __packed_union __packed union
229 //IAR compiler?
230 #elif defined(__IAR_SYSTEMS_ICC__)
231  #undef __packed_struct
232  #define __packed_struct __packed struct
233  #undef __packed_union
234  #define __packed_union __packed union
235 //Tasking compiler?
236 #elif defined(__TASKING__)
237  #undef __packed_struct
238  #define __packed_struct struct __packed__
239  #undef __packed_union
240  #define __packed_union union __packed__
241 //NXP CodeWarrior compiler?
242 #elif defined(__CWCC__)
243  #undef __packed_struct
244  #define __packed_struct struct
245  #undef __packed_union
246  #define __packed_union union
247 //Renesas CC-RX compiler?
248 #elif defined(__CCRX__)
249  #undef __packed_struct
250  #define __packed_struct struct
251  #undef __packed_union
252  #define __packed_union union
253 //TI CGT compiler?
254 #elif defined(__TI_COMPILER_VERSION__)
255  #undef __packed_struct
256  #define __packed_struct struct __attribute__((__packed__))
257  #undef __packed_union
258  #define __packed_union union __attribute__((__packed__))
259 //Win32 compiler?
260 #elif defined(_WIN32)
261  #undef interface
262  #undef __packed_struct
263  #define __packed_struct struct
264  #undef __packed_union
265  #define __packed_union union
266 #endif
267 
268 #ifndef __weak_func
269  //ARM compiler V6?
270  #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
271  #define __weak_func __attribute__((weak))
272  //GCC compiler?
273  #elif defined(__GNUC__)
274  #define __weak_func __attribute__((weak))
275  //ARM compiler?
276  #elif defined(__CC_ARM)
277  #define __weak_func __weak
278  //IAR compiler?
279  #elif defined(__IAR_SYSTEMS_ICC__)
280  #define __weak_func __weak
281  //Tasking compiler?
282  #elif defined(__TASKING__)
283  #define __weak_func __attribute__((weak))
284  //NXP CodeWarrior compiler?
285  #elif defined(__CWCC__)
286  #define __weak_func
287  //Renesas CC-RX compiler?
288  #elif defined(__CCRX__)
289  #define __weak_func
290  //TI CGT compiler?
291  #elif defined(__TI_COMPILER_VERSION__)
292  #define __weak_func __attribute__((weak))
293  //Win32 compiler?
294  #elif defined(_WIN32)
295  #define __weak_func
296  #endif
297 #endif
298 
299 //C++ guard
300 #ifdef __cplusplus
301 }
302 #endif
303 
304 #endif
int bool_t
Definition: compiler_port.h:63
signed int int_t
Definition: compiler_port.h:56
#define strncasecmp
uint16_t last
Definition: ipv4_frag.h:105
#define strtok_r(str, delim, p)
char char_t
Definition: compiler_port.h:55
uint8_t n
#define strcasecmp
uint8_t s
Definition: igmp_common.h:234
unsigned int uint_t
Definition: compiler_port.h:57