Home | History | Annotate | Line # | Download | only in include
      1   1.1  christos /* Symbol concatenation utilities.
      2   1.1  christos 
      3  1.10  christos    Copyright (C) 1998-2025 Free Software Foundation, Inc.
      4   1.1  christos 
      5   1.1  christos    This program is free software; you can redistribute it and/or modify
      6   1.1  christos    it under the terms of the GNU General Public License as published by
      7   1.1  christos    the Free Software Foundation; either version 2 of the License, or
      8   1.1  christos    (at your option) any later version.
      9   1.1  christos 
     10   1.1  christos    This program is distributed in the hope that it will be useful,
     11   1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   1.1  christos    GNU General Public License for more details.
     14   1.1  christos 
     15   1.1  christos    You should have received a copy of the GNU General Public License along
     16   1.1  christos    with this program; if not, write to the Free Software Foundation, Inc.,
     17   1.1  christos    51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
     18   1.1  christos 
     19   1.1  christos #ifndef SYM_CAT_H
     20   1.1  christos #define SYM_CAT_H
     21   1.1  christos 
     22   1.1  christos #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
     23   1.1  christos #define CONCAT2(a,b)	 a##b
     24   1.1  christos #define CONCAT3(a,b,c)	 a##b##c
     25   1.1  christos #define CONCAT4(a,b,c,d) a##b##c##d
     26   1.1  christos #define CONCAT5(a,b,c,d,e) a##b##c##d##e
     27   1.1  christos #define CONCAT6(a,b,c,d,e,f) a##b##c##d##e##f
     28   1.1  christos #define STRINGX(s) #s
     29   1.1  christos #else
     30   1.1  christos /* Note one should never pass extra whitespace to the CONCATn macros,
     31   1.1  christos    e.g. CONCAT2(foo, bar) because traditonal C will keep the space between
     32   1.1  christos    the two labels instead of concatenating them.  Instead, make sure to
     33   1.1  christos    write CONCAT2(foo,bar).  */
     34   1.1  christos #define CONCAT2(a,b)	 a/**/b
     35   1.1  christos #define CONCAT3(a,b,c)	 a/**/b/**/c
     36   1.1  christos #define CONCAT4(a,b,c,d) a/**/b/**/c/**/d
     37   1.1  christos #define CONCAT5(a,b,c,d,e) a/**/b/**/c/**/d/**/e
     38   1.1  christos #define CONCAT6(a,b,c,d,e,f) a/**/b/**/c/**/d/**/e/**/f
     39   1.1  christos #define STRINGX(s) "s"
     40   1.1  christos #endif
     41   1.1  christos 
     42   1.1  christos #define XCONCAT2(a,b)     CONCAT2(a,b)
     43   1.1  christos #define XCONCAT3(a,b,c)   CONCAT3(a,b,c)
     44   1.1  christos #define XCONCAT4(a,b,c,d) CONCAT4(a,b,c,d)
     45   1.1  christos #define XCONCAT5(a,b,c,d,e) CONCAT5(a,b,c,d,e)
     46   1.1  christos #define XCONCAT6(a,b,c,d,e,f) CONCAT6(a,b,c,d,e,f)
     47   1.1  christos 
     48   1.1  christos /* Note the layer of indirection here is typically used to allow
     49   1.1  christos    stringification of the expansion of macros.  I.e. "#define foo
     50   1.1  christos    bar", "XSTRING(foo)", to yield "bar".  Be aware that this only
     51   1.1  christos    works for __STDC__, not for traditional C which will still resolve
     52   1.1  christos    to "foo".  */
     53   1.1  christos #define XSTRING(s) STRINGX(s)
     54   1.1  christos 
     55   1.1  christos #endif /* SYM_CAT_H */
     56