Contiki-NG
cc.h
Go to the documentation of this file.
1/*
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.
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#ifdef CC_CONF_INLINE
52#define CC_INLINE CC_CONF_INLINE
53#else /* CC_CONF_INLINE */
54#define CC_INLINE
55#endif /* CC_CONF_INLINE */
56
57#ifdef CC_CONF_ALIGN
58#define CC_ALIGN(n) CC_CONF_ALIGN(n)
59#endif /* CC_CONF_INLINE */
60
61/**
62 * Configure if the C compiler supports functions that are not meant to return
63 * e.g. with __attribute__((__noreturn__))
64 */
65#ifdef CC_CONF_NORETURN
66#define CC_NORETURN CC_CONF_NORETURN
67#else
68#define CC_NORETURN
69#endif /* CC_CONF_NORETURN */
70
71/**
72 * Configure if the C compiler supports marking functions as deprecated
73 * e.g. with __attribute__((deprecated))
74 */
75#ifdef CC_CONF_DEPRECATED
76#define CC_DEPRECATED(msg) CC_CONF_DEPRECATED(msg)
77#else
78#define CC_DEPRECATED(msg)
79#endif /* CC_CONF_DEPRECATED */
80
81#if CC_CONF_NO_VA_ARGS
82#define CC_NO_VA_ARGS CC_CONF_VA_ARGS
83#endif
84
85/** \def CC_ACCESS_NOW(x)
86 * This macro ensures that the access to a non-volatile variable can
87 * not be reordered or optimized by the compiler.
89 * called ACCESS_ONCE
90 * The type must be passed, because the typeof-operator is a gcc
91 * extension
92 */
93
94#define CC_ACCESS_NOW(type, variable) (*(volatile type *)&(variable))
95
96#ifndef NULL
97#define NULL 0
98#endif /* NULL */
99
100#ifndef MAX
101#define MAX(n, m) (((n) < (m)) ? (m) : (n))
102#endif
103
104#ifndef MIN
105#define MIN(n, m) (((n) < (m)) ? (n) : (m))
106#endif
107
108#ifndef ABS
109#define ABS(n) (((n) < 0) ? -(n) : (n))
110#endif
111
112
113#define CC_CONCAT2(s1, s2) s1##s2
114/**
115 * A C preprocessing macro for concatenating two preprocessor tokens.
116 *
117 * We need use two macros (CC_CONCAT and CC_CONCAT2) in order to allow
118 * concatenation of two \#defined macros.
119 */
120#define CC_CONCAT(s1, s2) CC_CONCAT2(s1, s2)
121#define CC_CONCAT_EXT_2(s1, s2) CC_CONCAT2(s1, s2)
122
123/**
124 * A C preprocessing macro for concatenating three preprocessor tokens.
125 */
126#define CC_CONCAT3(s1, s2, s3) s1##s2##s3
127#define CC_CONCAT_EXT_3(s1, s2, s3) CC_CONCAT3(s1, s2, s3)
128
129#endif /* CC_H_ */