Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

.\"	$NetBSD: __CONCAT.3,v 1.8 2013/10/17 20:43:49 wiz Exp $ $
.\"
.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jukka Ruohonen.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd October 17, 2013
.Dt __CONCAT 3
.Os
.Sh NAME
.Nm __CONCAT ,
.Nm __STRING
.Nd argument substitution
.Sh SYNOPSIS
.In sys/cdefs.h
.Ft xy
.Fn __CONCAT "x" "y"
.Ft const char *
.Fn __STRING "x"
.Sh DESCRIPTION
The
.Nm
macro makes use of the
.Xr cpp 1
preprocessor to concatenate two tokens.
When the macro is expanded,
.Fa x
and
.Fa y
are combined into a single token, provided that the result forms a valid token;
two tokens that together do not form a valid token can not be concatenated.
This is known as
.Dq token concatenation
or
.Dq token pasting .
.Pp
The
.Fn __STRING
macro uses the conventional
.Sq #
preprocessing operator to replace the argument
.Fa x
with a string literal.
This is also known as
.Dq stringification .
.Sh EXAMPLES
The following two
.Xr printf 3
calls produce the same output:
.Bd -literal -offset indent
#define Net	0x01
#define	BSD	0x02

#define NetBSD	"NetBSD"

(void)printf("%s\en", __CONCAT(Net, BSD));
(void)printf("%s%s\en", __STRING(Net), __STRING(BSD));
.Ed
.Sh SEE ALSO
.Xr cpp 1 ,
.Xr cdefs 3
.Sh HISTORY
The
.Fn __CONCAT
and
.Fn __STRING
macros first appeared in
.Nx 1.3 .
.Sh CAVEATS
Many small details direct the proper use of the macros.
For example, while all leading and trailing whitespace is ignored when
.Fn __STRING
is used, it is undefined whether
.Xr cpp 1
puts white space between the tokens when
.Fn __CONCAT
is used.
It can be also noted that the C preprocessor converts all
comments to whitespace before any macros are even considered.
The use of either macro is discouraged in complex constructs.
.Pp
Use of this macro is non-portable; this is part of the implementation
namespace and should only be used in
.Nx
code.