C and C++


LANG.PREPROC.ICONST : Inappropriate Argument to Integer Constant Macro

Summary

The argument to an integer constant macro:

See also Use of <stdint.h> Small Integer Constant Macro.

Properties

Class Name Inappropriate Argument to Integer Constant Macro
Significance reliability
Mnemonic LANG.PREPROC.ICONST
Categories
MisraC2023 MisraC2023:7.5 The argument of an integer constant macro shall have an appropriate form
Misra2012 Misra2012:7.5 The argument of an integer constant macro shall have an appropriate form
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Inappropriate Argument to Integer Constant Macro"

Example

#include <stdint.h>

uint32_t g1 = UINT32_C(1);               /* ok */

uint32_t g2 = UINT32_C(-1);  /* 'Inappropriate Argument to Integer Constant Macro' warning issued here
                              * - macro name UNIT32_C indicates a 32-bit unsigned integer
                              * - argument -1 is not representable as a 32-bit unsigned integer
                              */

uint32_t g3 = UINT32_C(1u);  /* 'Inappropriate Argument to Integer Constant Macro' warning issued here
                              * - argument 1u has a literal suffix
                              */

uint32_t g4 = UINT32_C(1.0); /* 'Inappropriate Argument to Integer Constant Macro' warning issued here
                              * - argument is not an integer
                              */

uint32_t g5 = UINT32_C(g1);  /* 'Inappropriate Argument to Integer Constant Macro' warning issued here
                              * - argument is not a literal
                              */

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.