Rev 4921 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4349 | Serge | 1 | /* Provide support for both ANSI and non-ANSI environments. */ |
2 | |||
3 | /* Some ANSI environments are "broken" in the sense that __STDC__ cannot be |
||
4 | relied upon to have it's intended meaning. Therefore we must use our own |
||
5 | concoction: _HAVE_STDC. Always use _HAVE_STDC instead of __STDC__ in newlib |
||
6 | sources! |
||
7 | |||
8 | To get a strict ANSI C environment, define macro __STRICT_ANSI__. This will |
||
9 | "comment out" the non-ANSI parts of the ANSI header files (non-ANSI header |
||
10 | files aren't affected). */ |
||
11 | |||
12 | #ifndef _ANSIDECL_H_ |
||
13 | #define _ANSIDECL_H_ |
||
14 | |||
15 | #include |
||
16 | #include |
||
17 | |||
18 | /* First try to figure out whether we really are in an ANSI C environment. */ |
||
19 | /* FIXME: This probably needs some work. Perhaps sys/config.h can be |
||
20 | prevailed upon to give us a clue. */ |
||
21 | |||
22 | #ifdef __STDC__ |
||
23 | #define _HAVE_STDC |
||
24 | #endif |
||
25 | |||
26 | /* ISO C++. */ |
||
27 | |||
28 | #ifdef __cplusplus |
||
29 | #if !(defined(_BEGIN_STD_C) && defined(_END_STD_C)) |
||
30 | #ifdef _HAVE_STD_CXX |
||
31 | #define _BEGIN_STD_C namespace std { extern "C" { |
||
32 | #define _END_STD_C } } |
||
33 | #else |
||
34 | #define _BEGIN_STD_C extern "C" { |
||
35 | #define _END_STD_C } |
||
36 | #endif |
||
4921 | Serge | 37 | #if __GNUC_PREREQ (3, 3) |
6099 | serge | 38 | #define _NOTHROW __attribute__ ((__nothrow__)) |
4349 | Serge | 39 | #else |
40 | #define _NOTHROW throw() |
||
41 | #endif |
||
42 | #endif |
||
43 | #else |
||
44 | #define _BEGIN_STD_C |
||
45 | #define _END_STD_C |
||
46 | #define _NOTHROW |
||
47 | #endif |
||
48 | |||
49 | #ifdef _HAVE_STDC |
||
50 | #define _PTR void * |
||
51 | #define _AND , |
||
52 | #define _NOARGS void |
||
53 | #define _CONST const |
||
54 | #define _VOLATILE volatile |
||
55 | #define _SIGNED signed |
||
56 | #define _DOTS , ... |
||
57 | #define _VOID void |
||
58 | #ifdef __CYGWIN__ |
||
59 | #define _EXFUN_NOTHROW(name, proto) __cdecl name proto _NOTHROW |
||
60 | #define _EXFUN(name, proto) __cdecl name proto |
||
61 | #define _EXPARM(name, proto) (* __cdecl name) proto |
||
62 | #define _EXFNPTR(name, proto) (__cdecl * name) proto |
||
63 | #else |
||
64 | #define _EXFUN_NOTHROW(name, proto) name proto _NOTHROW |
||
65 | #define _EXFUN(name, proto) name proto |
||
66 | #define _EXPARM(name, proto) (* name) proto |
||
67 | #define _EXFNPTR(name, proto) (* name) proto |
||
68 | #endif |
||
69 | #define _DEFUN(name, arglist, args) name(args) |
||
70 | #define _DEFUN_VOID(name) name(_NOARGS) |
||
71 | #define _CAST_VOID (void) |
||
72 | #ifndef _LONG_DOUBLE |
||
73 | #define _LONG_DOUBLE long double |
||
74 | #endif |
||
75 | #ifndef _PARAMS |
||
76 | #define _PARAMS(paramlist) paramlist |
||
77 | #endif |
||
78 | #else |
||
79 | #define _PTR char * |
||
80 | #define _AND ; |
||
81 | #define _NOARGS |
||
82 | #define _CONST |
||
83 | #define _VOLATILE |
||
84 | #define _SIGNED |
||
85 | #define _DOTS |
||
86 | #define _VOID void |
||
87 | #define _EXFUN(name, proto) name() |
||
88 | #define _EXFUN_NOTHROW(name, proto) name() |
||
89 | #define _DEFUN(name, arglist, args) name arglist args; |
||
90 | #define _DEFUN_VOID(name) name() |
||
91 | #define _CAST_VOID |
||
92 | #define _LONG_DOUBLE double |
||
93 | #ifndef _PARAMS |
||
94 | #define _PARAMS(paramlist) () |
||
95 | #endif |
||
96 | #endif |
||
97 | |||
98 | /* Support gcc's __attribute__ facility. */ |
||
99 | |||
100 | #ifdef __GNUC__ |
||
101 | #define _ATTRIBUTE(attrs) __attribute__ (attrs) |
||
102 | #else |
||
103 | #define _ATTRIBUTE(attrs) |
||
104 | #endif |
||
105 | |||
106 | /* The traditional meaning of 'extern inline' for GCC is not |
||
107 | to emit the function body unless the address is explicitly |
||
108 | taken. However this behaviour is changing to match the C99 |
||
109 | standard, which uses 'extern inline' to indicate that the |
||
4921 | Serge | 110 | function body *must* be emitted. Likewise, a function declared |
111 | without either 'extern' or 'static' defaults to extern linkage |
||
112 | (C99 6.2.2p5), and the compiler may choose whether to use the |
||
113 | inline version or call the extern linkage version (6.7.4p6). |
||
114 | If we are using GCC, but do not have the new behaviour, we need |
||
115 | to use extern inline; if we are using a new GCC with the |
||
116 | C99-compatible behaviour, or a non-GCC compiler (which we will |
||
117 | have to hope is C99, since there is no other way to achieve the |
||
118 | effect of omitting the function if it isn't referenced) we use |
||
119 | 'static inline', which c99 defines to mean more-or-less the same |
||
120 | as the Gnu C 'extern inline'. */ |
||
4349 | Serge | 121 | #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__) |
122 | /* We're using GCC, but without the new C99-compatible behaviour. */ |
||
123 | #define _ELIDABLE_INLINE extern __inline__ _ATTRIBUTE ((__always_inline__)) |
||
124 | #else |
||
6099 | serge | 125 | /* We're using GCC in C99 mode, or an unknown compiler which |
4349 | Serge | 126 | we just have to hope obeys the C99 semantics of inline. */ |
4921 | Serge | 127 | #define _ELIDABLE_INLINE static __inline__ |
4349 | Serge | 128 | #endif |
129 | |||
4921 | Serge | 130 | #if __GNUC_PREREQ (3, 1) |
131 | #define _NOINLINE __attribute__ ((__noinline__)) |
||
132 | #define _NOINLINE_STATIC _NOINLINE static |
||
133 | #else |
||
134 | /* On non-GNU compilers and GCC prior to version 3.1 the compiler can't be |
||
135 | trusted not to inline if it is static. */ |
||
136 | #define _NOINLINE |
||
137 | #define _NOINLINE_STATIC |
||
138 | #endif |
||
139 | |||
4349 | Serge | 140 | #endif /* _ANSIDECL_H_ */ |