[metadata]
id = "EXP14-C"
type = "recommendation"
category = "EXP"
number = 14
title = "Beware of integer promotion when performing bitwise operations on integer types smaller than int"
description = """
DeprecatedThis guideline has been deprecated byINT02-C. Understand integer
conversion rules Integer types smaller thanintare promoted when an operation is
performed on them. If all values of the original type can be represented as
anint, the value of the smaller type is converted to anint; otherwise, it is
converted to anunsigned int(seeINT02-C. Understand integer conversion rules). If
the conversion is to a wider type, the original value is zero-extended for
unsigned values or sign-extended for signed types. Consequently, bitwise
operations on integer types smaller thanintmay have unexpected results. This
noncompliant code example demonstrates how performing bitwise operations on
integer types smaller thanintmay have unexpected results.
"""
severity = "low"
likelihood = "likely"
priority = "P3"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "Aug 06, 2025"
[rules.cert_c.EXP14-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/EXP14-C.+Beware+of+integer+promotion+when+performing+bitwise+operations+on+integer+types+smaller+than+int"