> ## 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.

# C Macro Concatenation

Macro concatenation in C is performed using the token-pasting operator (`##`) 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:

```c theme={"dark"}
#define CONCAT(a, b) a ## b
```

When invoked as `CONCAT(foo, bar)`, the preprocessor yields the single identifier token `foobar`.

## Technical Mechanics

1. **Whitespace Elimination:** The preprocessor removes all whitespace preceding and following the `##` operator, fusing the left and right operands.
2. **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.
3. **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.

```c theme={"dark"}
#define CONCAT(x, y) x ## y
#define PREFIX my_

// Yields the token: PREFIXsuffix (PREFIX is not expanded)
CONCAT(PREFIX, suffix) 
```

To force the preprocessor to expand arguments before concatenating them, you must use a two-level macro indirection. This forces the preprocessor to perform an argument prescan.

```c theme={"dark"}
#define CONCAT_PRIMITIVE(x, y) x ## y
#define CONCAT_EVALUATED(x, y) CONCAT_PRIMITIVE(x, y)

#define PREFIX my_

// Phase 1: CONCAT_EVALUATED expands arguments -> CONCAT_PRIMITIVE(my_, suffix)
// Phase 2: CONCAT_PRIMITIVE concatenates -> my_suffix
CONCAT_EVALUATED(PREFIX, suffix)
```

## 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.

```c theme={"dark"}
#define FUSE3(a, b, c) a ## b ## c

// Yields the single token: var_x_99
FUSE3(var, _x_, 99)
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
