Given the following code that prints a string which is a stringification of two words:
#define PORT_INFO_MAC_2(portNum) port: portNum
#define PORT_INFO_MAC(portNum) PORT_INFO_MAC_2(portNum)
/* Stringify macro expansion instead of the macro itself */
#define INVOKE_MACRO(...) #__VA_ARGS__
printf(" %s " , INVOKE_MACRO(PORT_INFO_MAC(1)) ); /* In a more general way, I'll be using it like follows: INVOKE_MACRO(PORT_INFO_MAC(2), PORT_INFO_MAC(1), ...) */
" port: 1 "
Why is there always a single space there and is there a way to control the amount of spaces?
Because that's what the stringification operator is specified to do:
If, in the replacement list, a parameter is immediately preceded by a
#preprocessing token, both are replaced by a single character string literal preprocessing token that contains the spelling of the preprocessing token sequence for the corresponding argument. Each occurrence of white space between the argument’s preprocessing tokens becomes a single space character in the character string literal.
(C2011 188.8.131.52/2; emphasis added)
Of course, if there is no whitespace at all between the preprocessing tokens, then none appears in the stringification.