[metadata]
id = "DCL19-C"
type = "recommendation"
category = "DCL"
number = 19
title = "Minimize the scope of variables and functions"
description = """
Variables and functions should be declared in the minimum scope from which all
references to the identifier are still possible. When a larger scope than
necessary is used, code becomes less readable, harder to maintain, and more
likely to reference unintended variables (seeDCL01-C. Do not reuse variable
names in subscopes). In this noncompliant code example, the
functioncounter()increments the global variablecountand then returns immediately
if this variable exceeds a maximum value:
"""
severity = "Low"
likelihood = "Unlikely"
priority = "P3"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 19, 2025"
[rules.cert_c.DCL19-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/DCL19-C.+Minimize+the+scope+of+variables+and+functions"