Gcc.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Gcc_H
  16. #define Gcc_H
  17. #if !defined(__clang__) && \
  18. defined(__GNUC__) && \
  19. (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4))
  20. #define Gcc_PRINTF( format_idx, arg_idx ) \
  21. __attribute__((__format__ (__printf__, format_idx, arg_idx)))
  22. #define Gcc_NORETURN \
  23. __attribute__((__noreturn__))
  24. #define Gcc_NONNULL(...) \
  25. __attribute__((__nonnull__(__VA_ARGS__)))
  26. #define Gcc_PURE \
  27. __attribute__ ((__pure__))
  28. #define Gcc_PACKED \
  29. __attribute__ ((packed))
  30. #define Gcc_ALLOC_SIZE(...) \
  31. __attribute__ ((alloc_size(__VA_ARGS__)))
  32. #define Gcc_USE_RET \
  33. __attribute__ ((warn_unused_result))
  34. #elif defined(__clang__)
  35. #define Gcc_NORETURN \
  36. __attribute__((__noreturn__))
  37. #define Gcc_USE_RET \
  38. __attribute__ ((warn_unused_result))
  39. #endif
  40. #ifndef Gcc_PRINTF
  41. #define Gcc_PRINTF( format_idx, arg_idx )
  42. #endif
  43. #ifndef Gcc_NORETURN
  44. #define Gcc_NORETURN
  45. #endif
  46. #ifndef Gcc_NONNULL
  47. #define Gcc_NONNULL(...)
  48. #endif
  49. #ifndef Gcc_PURE
  50. #define Gcc_PURE
  51. #endif
  52. #ifndef Gcc_PACKED
  53. #define Gcc_PACKED
  54. #endif
  55. #ifndef Gcc_ALLOC_SIZE
  56. #define Gcc_ALLOC_SIZE(...)
  57. #endif
  58. #ifndef Gcc_USE_RET
  59. #define Gcc_USE_RET
  60. #endif
  61. #define Gcc_SHORT_FILE <?js return '"'+__FILE__.substring(__FILE__.lastIndexOf('/')+1)+'"'; ?>
  62. #define Gcc_FILE Gcc_SHORT_FILE
  63. #define Gcc_LINE __LINE__
  64. Gcc_PRINTF(1,2)
  65. static inline void Gcc_checkPrintf(const char* format, ...)
  66. {
  67. // This does nothing except to trigger warnings if the format is wrong.
  68. }
  69. #endif