Human68k CUI emulator with sound.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ansidecl.h 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /* ANSI and traditional C compatability macros
  2. Copyright (C) 1991-2017 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  15. /* ANSI and traditional C compatibility macros
  16. ANSI C is assumed if __STDC__ is #defined.
  17. Macro ANSI C definition Traditional C definition
  18. ----- ---- - ---------- ----------- - ----------
  19. PTR `void *' `char *'
  20. const not defined `'
  21. volatile not defined `'
  22. signed not defined `'
  23. For ease of writing code which uses GCC extensions but needs to be
  24. portable to other compilers, we provide the GCC_VERSION macro that
  25. simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various
  26. wrappers around __attribute__. Also, __extension__ will be #defined
  27. to nothing if it doesn't work. See below. */
  28. #ifndef _ANSIDECL_H
  29. #define _ANSIDECL_H 1
  30. #ifdef __cplusplus
  31. extern "C" {
  32. #endif
  33. /* Every source file includes this file,
  34. so they will all get the switch for lint. */
  35. /* LINTLIBRARY */
  36. /* Using MACRO(x,y) in cpp #if conditionals does not work with some
  37. older preprocessors. Thus we can't define something like this:
  38. #define HAVE_GCC_VERSION(MAJOR, MINOR) \
  39. (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR)))
  40. and then test "#if HAVE_GCC_VERSION(2,7)".
  41. So instead we use the macro below and test it against specific values. */
  42. /* This macro simplifies testing whether we are using gcc, and if it
  43. is of a particular minimum version. (Both major & minor numbers are
  44. significant.) This macro will evaluate to 0 if we are not using
  45. gcc at all. */
  46. #ifndef GCC_VERSION
  47. #define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  48. #endif /* GCC_VERSION */
  49. #if defined (__STDC__) || defined(__cplusplus) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32)
  50. /* All known AIX compilers implement these things (but don't always
  51. define __STDC__). The RISC/OS MIPS compiler defines these things
  52. in SVR4 mode, but does not define __STDC__. */
  53. /* eraxxon@alumni.rice.edu: The Compaq C++ compiler, unlike many other
  54. C++ compilers, does not define __STDC__, though it acts as if this
  55. was so. (Verified versions: 5.7, 6.2, 6.3, 6.5) */
  56. #define PTR void *
  57. #undef const
  58. #undef volatile
  59. #undef signed
  60. /* inline requires special treatment; it's in C99, and GCC >=2.7 supports
  61. it too, but it's not in C89. */
  62. #undef inline
  63. #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) || (defined(__SUNPRO_C) && defined(__C99FEATURES__))
  64. /* it's a keyword */
  65. #else
  66. # if GCC_VERSION >= 2007
  67. # define inline __inline__ /* __inline__ prevents -pedantic warnings */
  68. # else
  69. # define inline /* nothing */
  70. # endif
  71. #endif
  72. #else /* Not ANSI C. */
  73. #define PTR char *
  74. /* some systems define these in header files for non-ansi mode */
  75. #undef const
  76. #undef volatile
  77. #undef signed
  78. #undef inline
  79. #define const
  80. #define volatile
  81. #define signed
  82. #define inline
  83. #endif /* ANSI C. */
  84. /* Define macros for some gcc attributes. This permits us to use the
  85. macros freely, and know that they will come into play for the
  86. version of gcc in which they are supported. */
  87. #if (GCC_VERSION < 2007)
  88. # define __attribute__(x)
  89. #endif
  90. /* Attribute __malloc__ on functions was valid as of gcc 2.96. */
  91. #ifndef ATTRIBUTE_MALLOC
  92. # if (GCC_VERSION >= 2096)
  93. # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
  94. # else
  95. # define ATTRIBUTE_MALLOC
  96. # endif /* GNUC >= 2.96 */
  97. #endif /* ATTRIBUTE_MALLOC */
  98. /* Attributes on labels were valid as of gcc 2.93 and g++ 4.5. For
  99. g++ an attribute on a label must be followed by a semicolon. */
  100. #ifndef ATTRIBUTE_UNUSED_LABEL
  101. # ifndef __cplusplus
  102. # if GCC_VERSION >= 2093
  103. # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED
  104. # else
  105. # define ATTRIBUTE_UNUSED_LABEL
  106. # endif
  107. # else
  108. # if GCC_VERSION >= 4005
  109. # define ATTRIBUTE_UNUSED_LABEL ATTRIBUTE_UNUSED ;
  110. # else
  111. # define ATTRIBUTE_UNUSED_LABEL
  112. # endif
  113. # endif
  114. #endif
  115. /* Similarly to ARG_UNUSED below. Prior to GCC 3.4, the C++ frontend
  116. couldn't parse attributes placed after the identifier name, and now
  117. the entire compiler is built with C++. */
  118. #ifndef ATTRIBUTE_UNUSED
  119. #if GCC_VERSION >= 3004
  120. # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
  121. #else
  122. #define ATTRIBUTE_UNUSED
  123. #endif
  124. #endif /* ATTRIBUTE_UNUSED */
  125. /* Before GCC 3.4, the C++ frontend couldn't parse attributes placed after the
  126. identifier name. */
  127. #if ! defined(__cplusplus) || (GCC_VERSION >= 3004)
  128. # define ARG_UNUSED(NAME) NAME ATTRIBUTE_UNUSED
  129. #else /* !__cplusplus || GNUC >= 3.4 */
  130. # define ARG_UNUSED(NAME) NAME
  131. #endif /* !__cplusplus || GNUC >= 3.4 */
  132. #ifndef ATTRIBUTE_NORETURN
  133. #define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
  134. #endif /* ATTRIBUTE_NORETURN */
  135. /* Attribute `nonnull' was valid as of gcc 3.3. */
  136. #ifndef ATTRIBUTE_NONNULL
  137. # if (GCC_VERSION >= 3003)
  138. # define ATTRIBUTE_NONNULL(m) __attribute__ ((__nonnull__ (m)))
  139. # else
  140. # define ATTRIBUTE_NONNULL(m)
  141. # endif /* GNUC >= 3.3 */
  142. #endif /* ATTRIBUTE_NONNULL */
  143. /* Attribute `returns_nonnull' was valid as of gcc 4.9. */
  144. #ifndef ATTRIBUTE_RETURNS_NONNULL
  145. # if (GCC_VERSION >= 4009)
  146. # define ATTRIBUTE_RETURNS_NONNULL __attribute__ ((__returns_nonnull__))
  147. # else
  148. # define ATTRIBUTE_RETURNS_NONNULL
  149. # endif /* GNUC >= 4.9 */
  150. #endif /* ATTRIBUTE_RETURNS_NONNULL */
  151. /* Attribute `pure' was valid as of gcc 3.0. */
  152. #ifndef ATTRIBUTE_PURE
  153. # if (GCC_VERSION >= 3000)
  154. # define ATTRIBUTE_PURE __attribute__ ((__pure__))
  155. # else
  156. # define ATTRIBUTE_PURE
  157. # endif /* GNUC >= 3.0 */
  158. #endif /* ATTRIBUTE_PURE */
  159. /* Use ATTRIBUTE_PRINTF when the format specifier must not be NULL.
  160. This was the case for the `printf' format attribute by itself
  161. before GCC 3.3, but as of 3.3 we need to add the `nonnull'
  162. attribute to retain this behavior. */
  163. #ifndef ATTRIBUTE_PRINTF
  164. #define ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) ATTRIBUTE_NONNULL(m)
  165. #define ATTRIBUTE_PRINTF_1 ATTRIBUTE_PRINTF(1, 2)
  166. #define ATTRIBUTE_PRINTF_2 ATTRIBUTE_PRINTF(2, 3)
  167. #define ATTRIBUTE_PRINTF_3 ATTRIBUTE_PRINTF(3, 4)
  168. #define ATTRIBUTE_PRINTF_4 ATTRIBUTE_PRINTF(4, 5)
  169. #define ATTRIBUTE_PRINTF_5 ATTRIBUTE_PRINTF(5, 6)
  170. #endif /* ATTRIBUTE_PRINTF */
  171. /* Use ATTRIBUTE_FPTR_PRINTF when the format attribute is to be set on
  172. a function pointer. Format attributes were allowed on function
  173. pointers as of gcc 3.1. */
  174. #ifndef ATTRIBUTE_FPTR_PRINTF
  175. # if (GCC_VERSION >= 3001)
  176. # define ATTRIBUTE_FPTR_PRINTF(m, n) ATTRIBUTE_PRINTF(m, n)
  177. # else
  178. # define ATTRIBUTE_FPTR_PRINTF(m, n)
  179. # endif /* GNUC >= 3.1 */
  180. # define ATTRIBUTE_FPTR_PRINTF_1 ATTRIBUTE_FPTR_PRINTF(1, 2)
  181. # define ATTRIBUTE_FPTR_PRINTF_2 ATTRIBUTE_FPTR_PRINTF(2, 3)
  182. # define ATTRIBUTE_FPTR_PRINTF_3 ATTRIBUTE_FPTR_PRINTF(3, 4)
  183. # define ATTRIBUTE_FPTR_PRINTF_4 ATTRIBUTE_FPTR_PRINTF(4, 5)
  184. # define ATTRIBUTE_FPTR_PRINTF_5 ATTRIBUTE_FPTR_PRINTF(5, 6)
  185. #endif /* ATTRIBUTE_FPTR_PRINTF */
  186. /* Use ATTRIBUTE_NULL_PRINTF when the format specifier may be NULL. A
  187. NULL format specifier was allowed as of gcc 3.3. */
  188. #ifndef ATTRIBUTE_NULL_PRINTF
  189. # if (GCC_VERSION >= 3003)
  190. # define ATTRIBUTE_NULL_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n)))
  191. # else
  192. # define ATTRIBUTE_NULL_PRINTF(m, n)
  193. # endif /* GNUC >= 3.3 */
  194. # define ATTRIBUTE_NULL_PRINTF_1 ATTRIBUTE_NULL_PRINTF(1, 2)
  195. # define ATTRIBUTE_NULL_PRINTF_2 ATTRIBUTE_NULL_PRINTF(2, 3)
  196. # define ATTRIBUTE_NULL_PRINTF_3 ATTRIBUTE_NULL_PRINTF(3, 4)
  197. # define ATTRIBUTE_NULL_PRINTF_4 ATTRIBUTE_NULL_PRINTF(4, 5)
  198. # define ATTRIBUTE_NULL_PRINTF_5 ATTRIBUTE_NULL_PRINTF(5, 6)
  199. #endif /* ATTRIBUTE_NULL_PRINTF */
  200. /* Attribute `sentinel' was valid as of gcc 3.5. */
  201. #ifndef ATTRIBUTE_SENTINEL
  202. # if (GCC_VERSION >= 3005)
  203. # define ATTRIBUTE_SENTINEL __attribute__ ((__sentinel__))
  204. # else
  205. # define ATTRIBUTE_SENTINEL
  206. # endif /* GNUC >= 3.5 */
  207. #endif /* ATTRIBUTE_SENTINEL */
  208. #ifndef ATTRIBUTE_ALIGNED_ALIGNOF
  209. # if (GCC_VERSION >= 3000)
  210. # define ATTRIBUTE_ALIGNED_ALIGNOF(m) __attribute__ ((__aligned__ (__alignof__ (m))))
  211. # else
  212. # define ATTRIBUTE_ALIGNED_ALIGNOF(m)
  213. # endif /* GNUC >= 3.0 */
  214. #endif /* ATTRIBUTE_ALIGNED_ALIGNOF */
  215. /* Useful for structures whose layout must match some binary specification
  216. regardless of the alignment and padding qualities of the compiler. */
  217. #ifndef ATTRIBUTE_PACKED
  218. # define ATTRIBUTE_PACKED __attribute__ ((packed))
  219. #endif
  220. /* Attribute `hot' and `cold' was valid as of gcc 4.3. */
  221. #ifndef ATTRIBUTE_COLD
  222. # if (GCC_VERSION >= 4003)
  223. # define ATTRIBUTE_COLD __attribute__ ((__cold__))
  224. # else
  225. # define ATTRIBUTE_COLD
  226. # endif /* GNUC >= 4.3 */
  227. #endif /* ATTRIBUTE_COLD */
  228. #ifndef ATTRIBUTE_HOT
  229. # if (GCC_VERSION >= 4003)
  230. # define ATTRIBUTE_HOT __attribute__ ((__hot__))
  231. # else
  232. # define ATTRIBUTE_HOT
  233. # endif /* GNUC >= 4.3 */
  234. #endif /* ATTRIBUTE_HOT */
  235. /* Attribute 'no_sanitize_undefined' was valid as of gcc 4.9. */
  236. #ifndef ATTRIBUTE_NO_SANITIZE_UNDEFINED
  237. # if (GCC_VERSION >= 4009)
  238. # define ATTRIBUTE_NO_SANITIZE_UNDEFINED __attribute__ ((no_sanitize_undefined))
  239. # else
  240. # define ATTRIBUTE_NO_SANITIZE_UNDEFINED
  241. # endif /* GNUC >= 4.9 */
  242. #endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */
  243. /* We use __extension__ in some places to suppress -pedantic warnings
  244. about GCC extensions. This feature didn't work properly before
  245. gcc 2.8. */
  246. #if GCC_VERSION < 2008
  247. #define __extension__
  248. #endif
  249. /* This is used to declare a const variable which should be visible
  250. outside of the current compilation unit. Use it as
  251. EXPORTED_CONST int i = 1;
  252. This is because the semantics of const are different in C and C++.
  253. "extern const" is permitted in C but it looks strange, and gcc
  254. warns about it when -Wc++-compat is not used. */
  255. #ifdef __cplusplus
  256. #define EXPORTED_CONST extern const
  257. #else
  258. #define EXPORTED_CONST const
  259. #endif
  260. /* Be conservative and only use enum bitfields with C++ or GCC.
  261. FIXME: provide a complete autoconf test for buggy enum bitfields. */
  262. #ifdef __cplusplus
  263. #define ENUM_BITFIELD(TYPE) enum TYPE
  264. #elif (GCC_VERSION > 2000)
  265. #define ENUM_BITFIELD(TYPE) __extension__ enum TYPE
  266. #else
  267. #define ENUM_BITFIELD(TYPE) unsigned int
  268. #endif
  269. #if __cpp_constexpr >= 200704
  270. #define CONSTEXPR constexpr
  271. #else
  272. #define CONSTEXPR
  273. #endif
  274. /* C++11 adds the ability to add "override" after an implementation of a
  275. virtual function in a subclass, to:
  276. (A) document that this is an override of a virtual function
  277. (B) allow the compiler to issue a warning if it isn't (e.g. a mismatch
  278. of the type signature).
  279. Similarly, it allows us to add a "final" to indicate that no subclass
  280. may subsequently override the vfunc.
  281. Provide OVERRIDE and FINAL as macros, allowing us to get these benefits
  282. when compiling with C++11 support, but without requiring C++11.
  283. For gcc, use "-std=c++11" to enable C++11 support; gcc 6 onwards enables
  284. this by default (actually GNU++14). */
  285. #if defined __cplusplus
  286. # if __cplusplus >= 201103
  287. /* C++11 claims to be available: use it. Final/override were only
  288. implemented in 4.7, though. */
  289. # if GCC_VERSION < 4007
  290. # define OVERRIDE
  291. # define FINAL
  292. # else
  293. # define OVERRIDE override
  294. # define FINAL final
  295. # endif
  296. # elif GCC_VERSION >= 4007
  297. /* G++ 4.7 supports __final in C++98. */
  298. # define OVERRIDE
  299. # define FINAL __final
  300. # else
  301. /* No C++11 support; leave the macros empty. */
  302. # define OVERRIDE
  303. # define FINAL
  304. # endif
  305. #else
  306. /* No C++11 support; leave the macros empty. */
  307. # define OVERRIDE
  308. # define FINAL
  309. #endif
  310. /* A macro to disable the copy constructor and assignment operator.
  311. When building with C++11 and above, the methods are explicitly
  312. deleted, causing a compile-time error if something tries to copy.
  313. For C++03, this just declares the methods, causing a link-time
  314. error if the methods end up called (assuming you don't
  315. define them). For C++03, for best results, place the macro
  316. under the private: access specifier, like this,
  317. class name_lookup
  318. {
  319. private:
  320. DISABLE_COPY_AND_ASSIGN (name_lookup);
  321. };
  322. so that most attempts at copy are caught at compile-time. */
  323. #if __cplusplus >= 201103
  324. #define DISABLE_COPY_AND_ASSIGN(TYPE) \
  325. TYPE (const TYPE&) = delete; \
  326. void operator= (const TYPE &) = delete
  327. #else
  328. #define DISABLE_COPY_AND_ASSIGN(TYPE) \
  329. TYPE (const TYPE&); \
  330. void operator= (const TYPE &)
  331. #endif /* __cplusplus >= 201103 */
  332. #ifdef __cplusplus
  333. }
  334. #endif
  335. #endif /* ansidecl.h */