my_attribute.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* Copyright (C) 2000-2003 MySQL AB
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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. /*
  19. Disable __attribute__() on gcc < 2.7, g++ < 3.4, and non-gcc compilers.
  20. Some forms of __attribute__ are actually supported in earlier versions of
  21. g++, but we just disable them all because we only use them to generate
  22. compilation warnings.
  23. */
  24. #ifndef __attribute__
  25. # if !defined(__GNUC__)
  26. # define __attribute__(A)
  27. # elif GCC_VERSION < 2008
  28. # define __attribute__(A)
  29. # elif defined(__cplusplus) && GCC_VERSION < 3004
  30. # define __attribute__(A)
  31. # endif
  32. #endif
  33. /*
  34. __attribute__((format(...))) is only supported in gcc >= 2.8 and g++ >= 3.4
  35. But that's already covered by the __attribute__ tests above, so this is
  36. just a convenience macro.
  37. */
  38. #ifndef ATTRIBUTE_FORMAT
  39. # define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n)))
  40. #endif
  41. /*
  42. __attribute__((format(...))) on a function pointer is not supported
  43. until gcc 3.1
  44. */
  45. #ifndef ATTRIBUTE_FORMAT_FPTR
  46. # if (GCC_VERSION >= 3001)
  47. # define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n)
  48. # else
  49. # define ATTRIBUTE_FORMAT_FPTR(style, m, n)
  50. # endif /* GNUC >= 3.1 */
  51. #endif
  52. #endif