Numeric constant defined with the preprocessor in C++

ID

c.maintainability.macro_constant_in_cpp

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Modern Alternative

Language

C / C++

Description

This numeric constant is defined with the preprocessor. A macro has no type and no scope: it is invisible to the debugger, cannot be namespaced or const-qualified, and silently replaces any identically-named token anywhere it is defined, including inside strings a linter would otherwise catch. Declare a constexpr variable instead — it is type-checked, scoped, and visible in a debugger.

Rationale

This numeric constant is defined with the preprocessor. A macro has no type and no scope: it is invisible to the debugger, cannot be namespaced or const-qualified, and silently replaces any identically-named token anywhere it is defined, including inside strings a linter would otherwise catch. Declare a constexpr variable instead — it is type-checked, scoped, and visible in a debugger.

The following code illustrates the pattern detected by this rule:

// FLAGGED: Numeric constant defined with the preprocessor in C++
#define MAX_SIZE 100

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved