Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  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 <newlib.h>
  16. #include <sys/config.h>
  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
  37. #if defined(__GNUC__) && \
  38.   ( (__GNUC__ >= 4) || \
  39.     ( (__GNUC__ >= 3) && defined(__GNUC_MINOR__) && (__GNUC_MINOR__ >= 3) ) )
  40. #define _NOTHROW __attribute__ ((nothrow))
  41. #else
  42. #define _NOTHROW throw()
  43. #endif
  44. #endif
  45. #else
  46. #define _BEGIN_STD_C
  47. #define _END_STD_C
  48. #define _NOTHROW
  49. #endif
  50.  
  51. #ifdef _HAVE_STDC
  52. #define _PTR            void *
  53. #define _AND            ,
  54. #define _NOARGS         void
  55. #define _CONST          const
  56. #define _VOLATILE       volatile
  57. #define _SIGNED         signed
  58. #define _DOTS           , ...
  59. #define _VOID void
  60. #ifdef __CYGWIN__
  61. #define _EXFUN_NOTHROW(name, proto)     __cdecl name proto _NOTHROW
  62. #define _EXFUN(name, proto)             __cdecl name proto
  63. #define _EXPARM(name, proto)            (* __cdecl name) proto
  64. #define _EXFNPTR(name, proto)           (__cdecl * name) proto
  65. #else
  66. #define _EXFUN_NOTHROW(name, proto)     name proto _NOTHROW
  67. #define _EXFUN(name, proto)             name proto
  68. #define _EXPARM(name, proto)            (* name) proto
  69. #define _EXFNPTR(name, proto)           (* name) proto
  70. #endif
  71. #define _DEFUN(name, arglist, args)     name(args)
  72. #define _DEFUN_VOID(name)               name(_NOARGS)
  73. #define _CAST_VOID (void)
  74. #ifndef _LONG_DOUBLE
  75. #define _LONG_DOUBLE long double
  76. #endif
  77. #ifndef _LONG_LONG_TYPE
  78. #define _LONG_LONG_TYPE long long
  79. #endif
  80. #ifndef _PARAMS
  81. #define _PARAMS(paramlist)              paramlist
  82. #endif
  83. #else  
  84. #define _PTR            char *
  85. #define _AND            ;
  86. #define _NOARGS
  87. #define _CONST
  88. #define _VOLATILE
  89. #define _SIGNED
  90. #define _DOTS
  91. #define _VOID void
  92. #define _EXFUN(name, proto)             name()
  93. #define _EXFUN_NOTHROW(name, proto)     name()
  94. #define _DEFUN(name, arglist, args)     name arglist args;
  95. #define _DEFUN_VOID(name)               name()
  96. #define _CAST_VOID
  97. #define _LONG_DOUBLE double
  98. #define _LONG_LONG_TYPE long
  99. #ifndef _PARAMS
  100. #define _PARAMS(paramlist)              ()
  101. #endif
  102. #endif
  103.  
  104. /* Support gcc's __attribute__ facility.  */
  105.  
  106. #ifdef __GNUC__
  107. #define _ATTRIBUTE(attrs) __attribute__ (attrs)
  108. #else
  109. #define _ATTRIBUTE(attrs)
  110. #endif
  111.  
  112. /*  The traditional meaning of 'extern inline' for GCC is not
  113.   to emit the function body unless the address is explicitly
  114.   taken.  However this behaviour is changing to match the C99
  115.   standard, which uses 'extern inline' to indicate that the
  116.   function body *must* be emitted.  If we are using GCC, but do
  117.   not have the new behaviour, we need to use extern inline; if
  118.   we are using a new GCC with the C99-compatible behaviour, or
  119.   a non-GCC compiler (which we will have to hope is C99, since
  120.   there is no other way to achieve the effect of omitting the
  121.   function if it isn't referenced) we just use plain 'inline',
  122.   which c99 defines to mean more-or-less the same as the Gnu C
  123.   'extern inline'.  */
  124. #if defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__)
  125. /* We're using GCC, but without the new C99-compatible behaviour.  */
  126. #define _ELIDABLE_INLINE extern __inline__ _ATTRIBUTE ((__always_inline__))
  127. #else
  128. /* We're using GCC in C99 mode, or an unknown compiler which
  129.   we just have to hope obeys the C99 semantics of inline.  */
  130. #define _ELIDABLE_INLINE __inline__
  131. #endif
  132.  
  133. #endif /* _ANSIDECL_H_ */
  134.