The C preprocessor operates on "tokens" and whenever there's a possibility of changing the meaning or ambiguity, it always adds whitespace in order to preserve the meaning.
Consider your example,
(B)
there's no ambiguity or meaning altering whether there's a space between ( and ) added or not irrespective of the macro value of B.
But it's not the case with
|B|
Depending on the macro B, this above could either be || or |something|. So preprocessor is forced to add a whitespace in order to keep C's lexical rules.
The same behaviour can be seen with any other token that could alter the meaning. For example,
#define B +
B+
would produce
+ +
as opposed to
++
for the said reason.
However, this is only the preprocessor that complies to C lexical rules. GCC does have and support an old preprocessor called traditional
processor which wouldn't add any extra whitespaces. For example, if you call preprocessor in traditional mode:
gcc -E -traditional-cpp file.c
then
#define B
(B)
|B|
produce (without the whitespace)
()
||
|and||are different operators. I hope someone writes an answer with exact rules the cpp uses.x | value | SOME_FLAGand it turns out to bex || SOME_FLAG, it's probably this way so it won't compile.||is treated as a special case. This could be avoided by always inserting spaces, which would not be against C rules (except for macro concatenations).