[metadata]
id = "EXP07-C"
type = "recommendation"
category = "EXP"
number = 7
title = "Do not diminish the benefits of constants by assuming their values in expressions"
description = """
If a constant value is given for an identifier, do not diminish the
maintainability of the code in which it is used by assuming its value in
expressions. Simply giving the constant a name is not enough to ensure
modifiability; you must be careful to always use the name, and remember that the
value can change. This recommendation is related toDCL06-C. Use meaningful
symbolic constants to represent literal values. The headerstdio.hdefines
theBUFSIZmacro, which expands to an integer constant expression that is the size
of the buffer used by thesetbuf()function. This noncompliant code example
defeats the purpose of definingBUFSIZas a constant by assuming its value in the
following expression: #include <stdio.h> /* ... */ nblocks = 1 + ((nbytes - 1)
>> 9); /* BUFSIZ = 512 = 2^9 */
"""
severity = "Low"
likelihood = "Unlikely"
priority = "P1"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 20, 2025"
[rules.cert_c.EXP07-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/EXP07-C.+Do+not+diminish+the+benefits+of+constants+by+assuming+their+values+in+expressions"