xref: /netbsd/share/man/man3/__CONCAT.3 (revision 6550d01e)
1.\"	$NetBSD: __CONCAT.3,v 1.6 2010/12/16 10:40:04 jruoho Exp $ $
2.\"
3.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Jukka Ruohonen.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd December 16, 2010
31.Dt __CONCAT 3
32.Os
33.Sh NAME
34.Nm __CONCAT ,
35.Nm __STRING
36.Nd argument substitution
37.Sh SYNOPSIS
38.In sys/cdefs.h
39.Ft xy
40.Fn __CONCAT "x" "y"
41.Ft const char *
42.Fn __STRING "x"
43.Sh DESCRIPTION
44The
45.Nm
46macro makes use of the
47.Xr cpp 1
48preprocessor to concatenate two tokens.
49When the macro is expanded,
50.Fa x
51and
52.Fa y
53are combined into a single token, provided that the result forms a valid token;
54two tokens that together do not form a valid token can not be concatenated.
55This is known as
56.Dq token concatenation
57or
58.Dq token pasting .
59.Pp
60The
61.Fn __STRING
62macro uses the conventional
63.Sq #
64preprocessing operator to replace the argument
65.Fa x
66with a string literal.
67This is also known as
68.Dq stringification .
69.Sh EXAMPLES
70The following two
71.Xr printf 3
72calls produce the same output:
73.Bd -literal -offset indent
74#define Net	0x01
75#define	BSD	0x02
76
77#define NetBSD	"NetBSD"
78
79(void)printf("%s\en", __CONCAT(Net, BSD));
80(void)printf("%s%s\en", __STRING(Net), __STRING(BSD));
81.Ed
82.Sh SEE ALSO
83.Xr cpp 1 ,
84.Xr cdefs 3
85.Sh HISTORY
86The
87.Fn __CONCAT
88and
89.Fn __STRING
90macros first appeared in
91.Nx 1.3 .
92.Sh CAVEATS
93Many small details direct the proper use of the macros.
94For example, while all leading and trailing whitespace is ignored when
95.Fn __STRING
96is used, it is undefined whether
97.Xr cpp 1
98puts white space between the tokens when
99.Fn __CONCAT
100is used.
101It can be also noted that the C preprocessor converts all
102comments to whitespace before any macros are even considered.
103The use of either macro is discouraged in complex constructs.
104