Macro concatenation in C is performed using the token-pasting operator (Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
##) during the preprocessing phase. It instructs the preprocessor to merge two adjacent tokens within a macro’s replacement list into a single, unified preprocessing token before the compiler begins syntactic or semantic analysis.
Syntax
The## operator is placed between two tokens in a macro definition:
CONCAT(foo, bar), the preprocessor yields the single identifier token foobar.
Technical Mechanics
- Whitespace Elimination: The preprocessor removes all whitespace preceding and following the
##operator, fusing the left and right operands. - Token Validity: The resulting concatenated sequence must form a valid C preprocessing token (e.g., an identifier, an integer constant, or a punctuator). If the fusion results in an invalid token (e.g., concatenating
+and_), the behavior is undefined, and modern compilers will typically halt with an error. - Placement Restrictions: The
##operator cannot appear at the absolute beginning or the absolute end of a macro replacement list.
Expansion and Evaluation Order
A critical mechanical rule of the C preprocessor is that macro arguments immediately adjacent to the## operator are not macro-expanded prior to concatenation. The preprocessor pastes the literal tokens passed to the macro.
Multiple Concatenations
Multiple## operators can be chained within a single replacement list. The C Standard specifies that the order of evaluation for multiple ## operators is unspecified. However, this rarely affects the final output provided all intermediate fusions result in valid preprocessing tokens.
Master C with Deep Grasping Methodology!Learn More





