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

Macro stringification is a C preprocessor mechanism that converts a function-like macro parameter into a string literal. This is achieved using the stringification operator (`#`), which instructs the preprocessor to enclose the exact text of the provided macro argument in double quotes during the macro expansion phase.

## Syntax

The `#` operator must precede the parameter name in the macro's replacement list. The `#` and the parameter name are evaluated as adjacent preprocessing tokens, meaning whitespace between them is perfectly valid and ignored by the preprocessor.

```c theme={"dark"}
#define STRINGIFY(param) #param
#define STRINGIFY_WITH_SPACE(param) # param
```

## Preprocessor Mechanics

When the preprocessor encounters the `#` operator, it applies specific lexical rules to the argument tokens before generating the string literal:

1. **Literal Conversion:** The raw text of the argument is wrapped in double quotes (`"`).
2. **Whitespace Normalization:** Leading and trailing whitespace around the argument is discarded. Multiple consecutive whitespace characters between tokens within the argument are collapsed into a single space.
3. **Automatic Escaping:** The preprocessor automatically inserts escape characters (`\`) for double quotes (`"`) and backslashes (`\`) *strictly* when those characters are already part of a string literal or a character constant token within the argument. Stray backslashes outside of these specific tokens are not escaped.

```c theme={"dark"}
#define TO_STRING(x) # x

// 1. Literal conversion
TO_STRING(hello) 
// Expands to: "hello"

// 2. Whitespace normalization
TO_STRING(  int   a  =   5;  ) 
// Expands to: "int a = 5;"

// 3. Automatic escaping (String literals)
TO_STRING(printf("Hello\n");) 
// Expands to: "printf(\"Hello\\n\");"

// 3. Automatic escaping (Character constants)
TO_STRING('\n')
// Expands to: "'\\n'"

// 3. No escaping for stray backslashes outside literals/constants
TO_STRING(\n)
// Expands to: "\n"
```

## Evaluation Order and Indirection

A critical mechanical behavior of the `#` operator is that it suppresses the macro expansion of its operand. If the argument passed to the stringified parameter is itself a macro, the preprocessor will stringify the macro's identifier, not its expanded value.

To stringify the *result* of an expanded macro, a two-level macro architecture (indirection) is required. This forces the preprocessor to evaluate the inner macro before applying the stringification operator.

```c theme={"dark"}
#define VERSION 17

// Level 1: Applies the # operator (suppresses expansion)
#define STR(x) #x

// Level 2: Forces argument expansion before passing to Level 1
#define XSTR(x) STR(x)

// Direct stringification: Argument is NOT expanded
STR(VERSION)  
// Expands to: "VERSION"

// Indirect stringification: Argument IS expanded first
XSTR(VERSION) 
// Step 1: XSTR(17)
// Step 2: STR(17)
// Expands to: "17"
```

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