1
0

Gcc.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Gcc_H
  16. #define Gcc_H
  17. #if !defined(__clang__) && \
  18. defined(__GNUC__) && \
  19. (__GNUC__ > 6)
  20. #define Gcc_FALLTHRU \
  21. __attribute__((fallthrough));
  22. #else
  23. #define Gcc_FALLTHRU
  24. #endif
  25. #if !defined(__clang__) && \
  26. defined(__GNUC__) && \
  27. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
  28. #define Gcc_PRINTF( format_idx, arg_idx ) \
  29. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  30. #define Gcc_NORETURN \
  31. __attribute__((__noreturn__))
  32. #define Gcc_NONNULL(...) \
  33. __attribute__((__nonnull__(__VA_ARGS__)))
  34. #define Gcc_PURE \
  35. __attribute__ ((__pure__))
  36. #define Gcc_PACKED \
  37. __attribute__ ((packed))
  38. #define Gcc_ALLOC_SIZE(...) \
  39. __attribute__ ((alloc_size(__VA_ARGS__)))
  40. #define Gcc_USE_RET \
  41. __attribute__ ((warn_unused_result))
  42. #elif defined(__clang__)
  43. #define Gcc_NORETURN \
  44. __attribute__((__noreturn__))
  45. #define Gcc_USE_RET \
  46. __attribute__ ((warn_unused_result))
  47. #endif
  48. #ifndef Gcc_PRINTF
  49. #define Gcc_PRINTF( format_idx, arg_idx )
  50. #endif
  51. #ifndef Gcc_NORETURN
  52. #define Gcc_NORETURN
  53. #endif
  54. #ifndef Gcc_NONNULL
  55. #define Gcc_NONNULL(...)
  56. #endif
  57. #ifndef Gcc_PURE
  58. #define Gcc_PURE
  59. #endif
  60. #ifndef Gcc_PACKED
  61. #define Gcc_PACKED
  62. #endif
  63. #ifndef Gcc_ALLOC_SIZE
  64. #define Gcc_ALLOC_SIZE(...)
  65. #endif
  66. #ifndef Gcc_USE_RET
  67. #define Gcc_USE_RET
  68. #endif
  69. #ifdef __INTELLISENSE__
  70. #define Gcc_SHORT_FILE __FILE__
  71. #else
  72. #define Gcc_SHORT_FILE <?js return '"'+__FILE__.substring(__FILE__.lastIndexOf('/')+1)+'"'; ?>
  73. #endif
  74. #define Gcc_FILE Gcc_SHORT_FILE
  75. #define Gcc_LINE __LINE__
  76. Gcc_PRINTF(1,2)
  77. static inline void Gcc_checkPrintf(const char* format, ...)
  78. {
  79. // This does nothing except to trigger warnings if the format is wrong.
  80. }
  81. #endif