cdefs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* $OpenBSD: cdefs.h,v 1.34 2012/08/14 20:11:37 matthew Exp $ */
  2. /* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */
  3. /*
  4. * Copyright (c) 1991, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is derived from software contributed to Berkeley by
  8. * Berkeley Software Design, Inc.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)cdefs.h 8.7 (Berkeley) 1/21/94
  35. */
  36. #ifndef _SYS_CDEFS_H_
  37. #define _SYS_CDEFS_H_
  38. /* Declaration field in C/C++ headers */
  39. #if defined(__cplusplus)
  40. # define __BEGIN_DECLS extern "C" {
  41. # define __END_DECLS }
  42. #else
  43. # define __BEGIN_DECLS
  44. # define __END_DECLS
  45. #endif
  46. #if defined(__STDC__) || defined(__cplusplus)
  47. # define __CONCAT(x,y) x ## y
  48. # define __STRING(x) #x
  49. #else
  50. # define __CONCAT(x,y) x/**/y
  51. # define __STRING(x) "x"
  52. #endif
  53. /*
  54. * Macro to test if we're using a specific version of gcc or later.
  55. */
  56. #if defined __GNUC__ && defined __GNUC_MINOR_
  57. # define __GNUC_PREREQ__(ma, mi) \
  58. ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
  59. #else
  60. # define __GNUC_PREREQ__(ma, mi) 0
  61. #endif
  62. /* Calling Convention: cdecl */
  63. #define _TLIBC_CDECL_
  64. /* Thread Directive */
  65. #define _TLIBC_THREAD_ /* __thread */
  66. /* Deprecated Warnings */
  67. #define _TLIBC_DEPRECATED_MSG(x) __STRING(x)" is deprecated in tlibc."
  68. #define _TLIBC_DEPRECATED_(x) __attribute__((deprecated(_TLIBC_DEPRECATED_MSG(x))))
  69. #ifndef _TLIBC_WARN_DEPRECATED_FUNCTIONS_
  70. # define _TLIBC_DEPRECATED_FUNCTION_(__ret, __func, ...)
  71. #else
  72. # define _TLIBC_DEPRECATED_FUNCTION_(__ret, __func, ...) \
  73. _TLIBC_DEPRECATED_(__func) \
  74. __ret __func(__VA_ARGS__)
  75. #endif
  76. /* Static analysis for printf format strings.
  77. * _MSC_PRINTF_FORMAT_: MSVC SAL annotation for specifying format strings.
  78. * _GCC_PRINTF_FORMAT_(x, y): GCC declaring attribute for checking format strings.
  79. * x - index of the format string. In C++ non-static method, index 1 is reseved for 'this'.
  80. * y - index of first variadic agrument in '...'.
  81. */
  82. #define _GCC_PRINTF_FORMAT_(x, y) __attribute__((__format__ (printf, x, y)))
  83. /* Attribute - noreturn */
  84. #define _TLIBC_NORETURN_ __attribute__ ((__noreturn__))
  85. /*
  86. * GNU C version 2.96 adds explicit branch prediction so that
  87. * the CPU back-end can hint the processor and also so that
  88. * code blocks can be reordered such that the predicted path
  89. * sees a more linear flow, thus improving cache behavior, etc.
  90. *
  91. * The following two macros provide us with a way to utilize this
  92. * compiler feature. Use __predict_true() if you expect the expression
  93. * to evaluate to true, and __predict_false() if you expect the
  94. * expression to evaluate to false.
  95. *
  96. * A few notes about usage:
  97. *
  98. * * Generally, __predict_false() error condition checks (unless
  99. * you have some _strong_ reason to do otherwise, in which case
  100. * document it), and/or __predict_true() `no-error' condition
  101. * checks, assuming you want to optimize for the no-error case.
  102. *
  103. * * Other than that, if you don't know the likelihood of a test
  104. * succeeding from empirical or other `hard' evidence, don't
  105. * make predictions.
  106. *
  107. * * These are meant to be used in places that are run `a lot'.
  108. * It is wasteful to make predictions in code that is run
  109. * seldomly (e.g. at subsystem initialization time) as the
  110. * basic block reordering that this affects can often generate
  111. * larger code.
  112. */
  113. #if defined(__GNUC__) && __GNUC_PREREQ__(2, 96)
  114. #define __predict_true(exp) __builtin_expect(((exp) != 0), 1)
  115. #define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
  116. #else
  117. #define __predict_true(exp) ((exp) != 0)
  118. #define __predict_false(exp) ((exp) != 0)
  119. #endif
  120. #endif /* !_SYS_CDEFS_H_ */