主要内容

MISRA C++:2008 Rule 2-13-4

Literal suffixes shall be upper case

Description

Rule Definition

Literal suffixes shall be upper case.1

Rationale

Literal constants can end with the letter l (el). Enforcing literal suffixes to be upper case removes potential confusion between the letter l and the digit 1.

For consistency, use upper case constants for other suffixes such as U (unsigned) and F (float).

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

Examples

expand all

const int a = 0l; //Noncompliant
const int b = 0L; //Compliant

In this example, both a and b are assigned the same literal constant. However, from a quick glance, one can mistakenly assume that a is assigned the value 01 (octal one).

Check Information

Group: Lexical Conventions
Category: Required

Version History

Introduced in R2013b


1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.

The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:

  • MISRA C:2004

  • MISRA C:2012

  • MISRA C:2023

  • MISRA C++:2008

  • MISRA C++:2023

MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.