79522404

Date: 2025-03-20 09:12:26
Score: 0.5
Natty:
Report link

No, according to the C standard, simply declaring a const variable without ever using it does not cause undefined behavior.

The presence of an unused const variable may lead to compiler warnings or the compiler optimizing it away, but the standard does not define this scenario as undefined behavior. It is purely a matter of optimization and static analysis, not correctness.

In short: Declaring an unused const variable is allowed and safe; it will not trigger undefined behavior.

Reasons:
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Alphin Thomas