Skip to content

MISRA-C - Do not use reserved names #9882

Closed
@ceolin

Description

@ceolin

The C standard reserves all identifiers that begin with an underscore for implementation details. Zephyr is using underscore for identifiers and macros all over the project resulting in many violations. Bellow a suggestion to handle this:

  • If a function is static, it is renamed so that the leading underscore is removed
  • If a function isn't static, a rule based on its name is used to rename the function based on its name:
    • _arch_ -> z_arch_
    • _sys_ -> z_sys_
    • _k_ -> z_
    • _impl_ -> z_sys_impl_
    • _handler_ -> z_sys_handl_
    • Otherwise, z_
    • Shortcuts such as "_current", "_ready_q", "_timeout_q" and "_threads" can be changed to their respective values.

According to the C Standard, 7.1.3 [ISO/IEC 9899:2011]

  • All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.
  • All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces.
  • Each macro name in any of the following subclauses (including the future library directions) is reserved for use as specified if any of its associated headers is included, unless explicitly stated otherwise.
  • All identifiers with external linkage (including future library directions) and errno are always reserved for use as identifiers with external linkage.

Part of #9552

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions