symcat.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Symbol concatenation utilities.
  2. Copyright (C) 1998-2020 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  14. #ifndef SYM_CAT_H
  15. #define SYM_CAT_H
  16. #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
  17. #define CONCAT2(a,b) a##b
  18. #define CONCAT3(a,b,c) a##b##c
  19. #define CONCAT4(a,b,c,d) a##b##c##d
  20. #define CONCAT5(a,b,c,d,e) a##b##c##d##e
  21. #define CONCAT6(a,b,c,d,e,f) a##b##c##d##e##f
  22. #define STRINGX(s) #s
  23. #else
  24. /* Note one should never pass extra whitespace to the CONCATn macros,
  25. e.g. CONCAT2(foo, bar) because traditonal C will keep the space between
  26. the two labels instead of concatenating them. Instead, make sure to
  27. write CONCAT2(foo,bar). */
  28. #define CONCAT2(a,b) a/**/b
  29. #define CONCAT3(a,b,c) a/**/b/**/c
  30. #define CONCAT4(a,b,c,d) a/**/b/**/c/**/d
  31. #define CONCAT5(a,b,c,d,e) a/**/b/**/c/**/d/**/e
  32. #define CONCAT6(a,b,c,d,e,f) a/**/b/**/c/**/d/**/e/**/f
  33. #define STRINGX(s) "s"
  34. #endif
  35. #define XCONCAT2(a,b) CONCAT2(a,b)
  36. #define XCONCAT3(a,b,c) CONCAT3(a,b,c)
  37. #define XCONCAT4(a,b,c,d) CONCAT4(a,b,c,d)
  38. #define XCONCAT5(a,b,c,d,e) CONCAT5(a,b,c,d,e)
  39. #define XCONCAT6(a,b,c,d,e,f) CONCAT6(a,b,c,d,e,f)
  40. /* Note the layer of indirection here is typically used to allow
  41. stringification of the expansion of macros. I.e. "#define foo
  42. bar", "XSTRING(foo)", to yield "bar". Be aware that this only
  43. works for __STDC__, not for traditional C which will still resolve
  44. to "foo". */
  45. #define XSTRING(s) STRINGX(s)
  46. #endif /* SYM_CAT_H */