Skip to content

Feature: Support nested macros in cc45 preprocessor #233

Description

@CTalkobt

Feature Request

Component: cc45 (C Compiler Preprocessor) / cp45 (Preprocessor)

Description:
Add support for nested macro definitions and invocations in the cc45 C preprocessor.

Currently, the cc45 preprocessor supports standard C preprocessor macros, but does not reliably handle macros defined within other macros (nested macro definitions) or complex multi-level macro invocations.

Use Case:
Complex C codebases benefit from hierarchical macro abstractions for:

  • Building library macros that compose smaller utility macros
  • Parameterized code generation at multiple levels
  • Conditional compilation strategies that depend on macro nesting

Example Desired Syntax:

#define BASE_SETUP() \
  do { \
    asm volatile("pha"); \
    asm volatile("phx"); \
  } while(0)

#define FULL_SETUP(flag) \
  do { \
    BASE_SETUP(); \
    if (flag) { \
      asm volatile("phy"); \
    } \
  } while(0)

Implementation Considerations:

  • Ensure proper macro argument expansion at each nesting level
  • Handle edge cases with stringification (#) and token pasting (##) in nested macros
  • Prevent infinite recursion with nesting depth limits or cycle detection
  • Maintain compatibility with C99/C11 preprocessor standards
  • Consider performance impact on preprocessing time
  • Test compatibility with GCC and Clang preprocessor behavior

Related Documentation:

Priority: Medium (code organization improvement)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions