my_attribute.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation; version 2 of the License.
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License
  10. along with this program; if not, write to the Free Software
  11. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  12. /*
  13. Helper macros used for setting different __attributes__
  14. on functions in a portable fashion
  15. */
  16. #ifndef _my_attribute_h
  17. #define _my_attribute_h
  18. #if defined(__GNUC__)
  19. # ifndef GCC_VERSION
  20. # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  21. # endif
  22. #endif
  23. /*
  24. Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers.
  25. Some forms of __attribute__ are actually supported in earlier versions of
  26. g++, but we just disable them all because we only use them to generate
  27. compilation warnings.
  28. */
  29. #ifndef __attribute__
  30. # if !defined(__GNUC__)
  31. # define __attribute__(A)
  32. # else
  33. # ifndef GCC_VERSION
  34. # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
  35. # endif
  36. # if GCC_VERSION < 2008
  37. # define __attribute__(A)
  38. # elif defined(__cplusplus) && GCC_VERSION < 3004
  39. # define __attribute__(A)
  40. # endif
  41. # endif
  42. #endif
  43. /*
  44. __attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4
  45. But that's already covered by the __attribute__ tests above, so this is
  46. just a convenience macro.
  47. */
  48. #ifndef ATTRIBUTE_FORMAT
  49. # define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n)))
  50. #endif
  51. /*
  52. __attribute__((format(...))) on a function pointer is not supported
  53. until gcc 3.1
  54. */
  55. #ifndef ATTRIBUTE_FORMAT_FPTR
  56. # if (GCC_VERSION >= 3001)
  57. # define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n)
  58. # else
  59. # define ATTRIBUTE_FORMAT_FPTR(style, m, n)
  60. # endif /* GNUC >= 3.1 */
  61. #endif
  62. #endif