[metadata]
id = "PRE05-C"
type = "recommendation"
category = "PRE"
number = 5
title = "Understand macro replacement when concatenating tokens or performing stringification"
description = """
It is necessary to understand how macro replacement works in C, particularly in
the context of concatenating tokens using the##operator and converting macro
parameters to strings using the#operator. The##preprocessing operator is used to
merge two tokens into one while expanding macros, which is calledtoken
pastingortoken concatenation. When a macro is expanded, the two tokens on either
side of each##operator are combined into a single token that replaces the##and
the two original tokens in the macro expansion [FSF 2005]. Token pasting is most
useful when one or both of the tokens come from a macro argument. If either of
the tokens next to a##is a parameter name, it is replaced by its actual argument
before##executes. The actual argument is not macro expanded first.
"""
severity = "Low"
likelihood = "Unlikely"
priority = "P2"
level = "L3"
cert_version = "2016 Edition (Wiki)"
last_modified = "May 19, 2025"
[rules.cert_c.PRE05-C]
enabled = true
[references]
wiki = "https://wiki.sei.cmu.edu/confluence/display/c/PRE05-C.+Understand+macro+replacement+when+concatenating+tokens+or+performing+stringification"