comparison src/compiler.h @ 1743:543769b89fed

[xemacs-hg @ 2003-10-14 05:02:57 by james] New compiler.h contains compiler-specific defines. Use it everywhere.
author james
date Tue, 14 Oct 2003 05:03:13 +0000
parents
children e4f996d69637
comparison
equal deleted inserted replaced
1742:7f92ee59c996 1743:543769b89fed
1 /* Compiler-specific definitions for XEmacs.
2 Copyright (C) 1998-1999, 2003 Free Software Foundation, Inc.
3 Copyright (C) 1994 Richard Mlynarik.
4
5 This file is part of XEmacs.
6
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
10 later version.
11
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 /* Synched up with: not in FSF. */
23
24 /* Authorship:
25
26 NOT_REACHED, DOESNT_RETURN, PRINTF_ARGS by Richard Mlynarik, c. 1994.
27 RETURN_SANS_WARNING by Martin buchholz, 1998 or 1999.
28 Many changes and improvements by Jerry James, 2003.
29 Split out of lisp.h, reorganized, and modernized.
30 {BEGIN,END}_C_DECLS, NEED_GCC, GCC_VERSION
31 ATTRIBUTE_MALLOC, ATTRIBUTE_CONST, ATTRIBUTE_PURE, UNUSED_ARG
32 */
33
34 #ifndef INCLUDED_compiler_h
35 #define INCLUDED_compiler_h
36
37 /* Define min() and max(). (Some compilers put them in strange places that
38 won't be referenced by include files used by XEmacs, such as 'macros.h'
39 under Solaris.) */
40
41 #ifndef min
42 #define min(a,b) (((a) <= (b)) ? (a) : (b))
43 #endif
44 #ifndef max
45 #define max(a,b) (((a) > (b)) ? (a) : (b))
46 #endif
47
48 /* Regular C complains about possible clobbering of local vars NOT declared
49 as volatile if there's a longjmp() in a function. C++ complains if such
50 vars ARE volatile; or more correctly, sans volatile no problem even when
51 you longjmp, avec volatile you get unfixable compile errors like
52
53 /src/xemacs/lilfix/src/process-unix.c: In function `void
54 unix_send_process(Lisp_Object, lstream*)':
55 /src/xemacs/lilfix/src/process-unix.c:1577: no matching function for call to `
56 Lisp_Object::Lisp_Object(volatile Lisp_Object&)'
57 /src/xemacs/lilfix/src/lisp-union.h:32: candidates are:
58 Lisp_Object::Lisp_Object(const Lisp_Object&)
59 */
60
61 #ifdef __cplusplus
62 #define VOLATILE_IF_NOT_CPP
63 #else
64 #define VOLATILE_IF_NOT_CPP volatile
65 #endif
66
67 /* Avoid indentation problems when XEmacs sees the curly braces */
68 #ifndef BEGIN_C_DECLS
69 # ifdef __cplusplus
70 # define BEGIN_C_DECLS extern "C" {
71 # define END_C_DECLS }
72 # else
73 # define BEGIN_C_DECLS
74 # define END_C_DECLS
75 # endif
76 #endif
77
78 /* Macro simplification for non-GNU compilers */
79 #ifndef __GNUC__
80 #define __GNUC__ 0
81 #define __GNUC_MINOR__ 0
82 #define __GNUC_PATCHLEVEL__ 0
83 #endif /* __GNUC__ */
84
85 /* Simplify testing for specific GCC versions. This also works for non-GCC
86 compilers, where GCC_VERSION is zero. */
87 #ifndef NEED_GCC
88 #define NEED_GCC(major,minor,patch) (major * 1000000 + minor * 1000 + patch)
89 #endif /* NEED_GCC */
90 #ifndef GCC_VERSION
91 #define GCC_VERSION NEED_GCC (__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
92 #endif /* GCC_VERSION */
93
94 /* GCC < 2.6.0 could only declare one attribute per function. In that case,
95 we define DOESNT_RETURN in preference to PRINTF_ARGS, which is only used
96 for checking args against the string spec. */
97 #ifndef PRINTF_ARGS
98 # if (GCC_VERSION >= NEED_GCC (2, 6, 0))
99 # define PRINTF_ARGS(string_index,first_to_check) \
100 __attribute__ ((format (printf, string_index, first_to_check)))
101 # else
102 # define PRINTF_ARGS(string_index,first_to_check)
103 # endif /* GNUC */
104 #endif
105
106 #ifndef DOESNT_RETURN
107 # if (GCC_VERSION > NEED_GCC (0, 0, 0))
108 # if (GCC_VERSION >= NEED_GCC (2, 5, 0))
109 # if (GCC_VERSION < NEED_GCC (3, 0, 0))
110 /* GCC 3.2 -O3 issues complaints in Fcommand_loop_1 about no return
111 statement if we have this definition */
112 # define RETURN_NOT_REACHED(value) DO_NOTHING
113 # endif
114 # define DOESNT_RETURN void
115 # define DECLARE_DOESNT_RETURN(decl) void decl __attribute__ ((noreturn))
116 # else /* GCC_VERSION < NEED_GCC (2, 5, 0) */
117 # define DOESNT_RETURN void volatile
118 # define DECLARE_DOESNT_RETURN(decl) void volatile decl
119 # endif /* GCC_VERSION >= NEED_GCC (2, 5, 0) */
120 # else /* not gcc */
121 # define DOESNT_RETURN void
122 # define DECLARE_DOESNT_RETURN(decl) void decl
123 # endif /* GCC_VERSION > NEED_GCC (0, 0, 0) */
124 #endif /* DOESNT_RETURN */
125
126 /* Another try to fix SunPro C compiler warnings */
127 /* "end-of-loop code not reached" */
128 /* "statement not reached */
129 #if defined __SUNPRO_C || defined __USLC__
130 #define RETURN_SANS_WARNINGS if (1) return
131 #define RETURN_NOT_REACHED(value) DO_NOTHING
132 #endif
133
134 /* More ways to shut up compiler. This works in Fcommand_loop_1(),
135 where there's an infinite loop in a function returning a Lisp object.
136 */
137 #if defined (_MSC_VER) || defined (__SUNPRO_C) || defined (__SUNPRO_CC) || \
138 (defined (DEC_ALPHA) && defined (OSF1))
139 #define DO_NOTHING_DISABLING_NO_RETURN_WARNINGS if (0) return Qnil
140 #else
141 #define DO_NOTHING_DISABLING_NO_RETURN_WARNINGS DO_NOTHING
142 #endif
143
144 #ifndef RETURN_NOT_REACHED
145 #define RETURN_NOT_REACHED(value) return (value)
146 #endif
147
148 #ifndef RETURN_SANS_WARNINGS
149 #define RETURN_SANS_WARNINGS return
150 #endif
151
152 #ifndef DO_NOTHING
153 #define DO_NOTHING do {} while (0)
154 #endif
155
156 #ifndef DECLARE_NOTHING
157 #define DECLARE_NOTHING struct nosuchstruct
158 #endif
159
160 #ifndef ATTRIBUTE_MALLOC
161 # if (GCC_VERSION >= NEED_GCC (2, 96, 0))
162 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
163 # else
164 # define ATTRIBUTE_MALLOC
165 # endif /* GCC_VERSION >= NEED_GCC (2, 96, 0) */
166 #endif /* ATTRIBUTE_MALLOC */
167
168 #ifndef ATTRIBUTE_PURE
169 # if (GCC_VERSION >= NEED_GCC (2, 96, 0))
170 # define ATTRIBUTE_PURE __attribute__ ((pure))
171 # else
172 # define ATTRIBUTE_PURE
173 # endif /* GCC_VERSION >= NEED_GCC (2, 96, 0) */
174 #endif /* ATTRIBUTE_PURE */
175
176 #ifndef ATTRIBUTE_CONST
177 # if (GCC_VERSION >= NEED_GCC (2, 5, 0))
178 # define ATTRIBUTE_CONST __attribute__ ((const))
179 # define CONST_FUNC
180 # else
181 # define ATTRIBUTE_CONST
182 # define CONST_FUNC const
183 # endif /* GCC_VERSION >= NEED_GCC (2, 5, 0) */
184 #endif /* ATTRIBUTE_CONST */
185
186 /* Unused declarations; g++ doesn't support this. */
187 #ifndef UNUSED_ARG
188 # if defined(__GNUC__) && !defined(__cplusplus)
189 # define UNUSED_ARG __attribute__ ((unused))
190 # else
191 # define UNUSED_ARG
192 # endif
193 #endif /* ATTRIBUTE_UNUSED */
194
195 #ifdef DEBUG_XEMACS
196 #define REGISTER
197 #define register
198 #else
199 #define REGISTER register
200 #endif
201
202 #if defined(HAVE_MS_WINDOWS) && defined(HAVE_SHLIB)
203 # ifdef EMACS_MODULE
204 # define MODULE_API __declspec(dllimport)
205 # else
206 # define MODULE_API __declspec(dllexport)
207 # endif
208 #else
209 # define MODULE_API
210 #endif
211
212 #endif /* INCLUDED_compiler_h */