Skip to content

Commit 6826d71

Browse files
committed
doc: coding guidelines: Add a new rule for macro name collisions
This commit is the outcome of the discussion that has taken place in multiple forums: Discord: https://discord.com/channels/720317445772017664/1014241011989487716/1032623375228608522 GitHub: zephyrproject-rtos#51371 zephyrproject-rtos#50239 Signed-off-by: Carles Cufi <[email protected]>
1 parent 33b0c0d commit 6826d71

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

doc/contribute/coding_guidelines/index.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,48 @@ Related GitHub Issues and Pull Requests are tagged with the `Inclusive Language
12551255
.. _CAN in Automation Inclusive Language news post: https://www.can-cia.org/news/archive/view/?tx_news_pi1%5Bnews%5D=699&tx_news_pi1%5Bday%5D=6&tx_news_pi1%5Bmonth%5D=12&tx_news_pi1%5Byear%5D=2020&cHash=784e79eb438141179386cf7c29ed9438
12561256
.. _CAN in Automation Inclusive Language: https://can-newsletter.org/canopen/categories/
12571257

1258+
1259+
Rule A.3: Macro name collisions
1260+
===============================
1261+
1262+
Severity
1263+
--------
1264+
1265+
Required
1266+
1267+
Description
1268+
-----------
1269+
1270+
Macros with commonly used names such as ``MIN``, ``MAX``, ``ARRAY_SIZE``, must
1271+
not be modified or protected to avoid name collisions with other
1272+
implementations. In particular, they must not be prefixed to place them in a
1273+
Zephyr-specific namespace, re-defined using ``#undef``, or conditionally
1274+
excluded from compilation using ``#ifndef``. Instead, if a conflict arises with
1275+
an existing definition originating from a :ref:`module <modules>`, the module's
1276+
code itself needs to be modified (ideally upstream, alternatively via a change
1277+
in Zephyr's own fork).
1278+
This rule applies to Zephyr as a project in general, regardless of the time of
1279+
introduction of the macro or its current name in the tree. If a macro name is
1280+
commonly used in several other well-known open source projects then the
1281+
implementation in Zephyr should use that name. While there is a subjective and
1282+
non-measurable component to what "commonly used" means, the ultimate goal is
1283+
to offer users familiar macros.
1284+
Finally, this rule applies to inter-module name collisions as well: in that case
1285+
both modules, prior to their inclusion, should be modified to use
1286+
module-specific versions of the macro name that collides.
1287+
1288+
Rationale
1289+
---------
1290+
1291+
Zephyr is an RTOS that comes with additional functionality and dependencies in
1292+
the form of modules. Those modules are typically independent projects that may
1293+
use macro names that can conflict with other modules or with Zephyr itself.
1294+
Since, in the context of this documentation, Zephyr is considered the central or
1295+
main project, it should implement the non-namespaced versions of the
1296+
macros. Given that Zephyr uses a fork of the corresponding upstream for each
1297+
module, it is always possible to patch the macro implementation in each module
1298+
to avoid collisions.
1299+
12581300
Parasoft Codescan Tool
12591301
**********************
12601302

0 commit comments

Comments
 (0)