__CONCAT(3)
π
__CONCAT(3) β okay bestie, let's talk about the __CONCAT and __STRING macros
So this is a page from the Library Functions Manual (the 3 in __CONCAT(3) is giving "section 3, library functions" β¨). Sit down, grab a strawberry π, and let's get into it.
πΈ NAME πΈ
__CONCAT, __STRING β argument substitution, but make it preprocessor chic π
β¨ SYNOPSIS β¨
#include <sys/cdefs.h>
xy
__CONCAT(x, y);
const char *
__STRING(x);
(Yes, xy up there is literally the return-type placeholder from the page β I'm not touching it, she stays exactly as written π
)
π DESCRIPTION π
Okay so first up, the __CONCAT macro. It's lowkey just vibing with the cpp(1) preprocessor to glue two tokens together. When the macro expands, x and y get combined into a single token β but only if the result actually forms a valid token. If the two tokens together don't make a valid token, then nope, they can't be concatenated, periodt. This whole thing is known as "token concatenation" or "token pasting". π«Ά
Then there's __STRING(), the icon. It uses the conventional '#' preprocessing operator to swap the argument x out for a string literal. She's also known as "stringification". Slay. π
π¦ EXAMPLES π¦
Not me showing you that these two printf(3) calls produce the same output π :
#define Net 0x01
#define BSD 0x02
#define NetBSD "NetBSD"
(void)printf("%s\n", __CONCAT(Net, BSD));
(void)printf("%s%s\n", __STRING(Net), __STRING(BSD));
Same output, two different vibes. Main character energy from both fr fr. π
π SEE ALSO π
Go read them, iykyk π
π HISTORY π
The __CONCAT() and __STRING() macros first appeared in NetBSD 1.3. Little baby macros, all grown up now ππ
π₯ CAVEATS π₯
Bestie, listen to me carefully, because there are many small details that direct the proper use of these macros and I need you to focus π:
- While all leading and trailing whitespace is ignored when
__STRING()is used, it is undefined whethercpp(1)puts white space between the tokens when__CONCAT()is used. Undefined! Do not come crying to me about whitespace. π - Also worth noting: the C preprocessor converts all comments to whitespace before any macros are even considered.
- The use of either macro is discouraged in complex constructs. Keep it simple, keep it cute. π§
Use of this macro is non-portable β she is part of the implementation namespace and should only be used in NetBSD code. No sneaking her into your portable project, ngl. π¨
β π β
And that's the page! Source/version and date, for the record: this one's from Debian, dated October 17, 2013 β so yes, she's an elder icon but she still ate. Byeee π«Άππ
π¦ where this page comes from
- nixpkgs unstable: netbsd-source 11.0
- Copyright (c) 2010 The NetBSD Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms