JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


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

要旨

The argument to an integer constant macro:

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

プロパティ

クラス名 Inappropriate Argument to Integer Constant Macro
日本語クラス名 Inappropriate Argument to Integer Constant Macro
クラス分類 信頼性 (reliability)
ニーモニック LANG.PREPROC.ICONST
カテゴリー
MisraC2025 MisraC2025:7.5 The argument of an integer constant macro shall have an appropriate form
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
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Inappropriate Argument to Integer Constant Macro"

#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
                              */


/* These statements will cause errors in many compilers.
 * We guard them with "#ifdef __CODESONAR__ ... #endif" so that they
 * are preprocessed out by the native compiler (so the example can be compiled)
 * but still observed by the CodeSonar analysis.
 */

#ifdef __CODESONAR__

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
                              */
#endif

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.