_ansi.h 4.2 KB

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