It's common practice to define stringizing macros like:
#define str(token) #token
#define xstr(token) str(token)
Why is the x
prefix typically used? Is there any meaning to "x"?
(My guess would be that maybe it stands for "expanded" (if anything), but I have no evidence to back that up.)
As others have suggested, the x
seems to be used for extended or I've also seen expanded used as well. An article on Stringizing by GNU has a reference to this use.
They phrase it as:
"If you want to stringize the result [...], you have to use two levels of macros."
#define xstr(s) str(s)
#define str(s) #s
#define foo 4
str (foo)
→ "foo"
xstr (foo)
→ xstr (4)
→ str (4)
→ "4"
They continue to state:
"s is stringized when it is used in str, so it is not macro-expanded first. But s is an ordinary argument to xstr, so it is completely macro-expanded before xstr itself is expanded (see Argument Prescan). Therefore, by the time str gets to its argument, it has already been macro-expanded."
While none of this is concrete, I think you're safe to assume x is expanded/extended usage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With