[previous] 0580 [next] [C] Constant is too large to be representable.
Constraint violations REFERENCE - ISO:C90-6.4 Constant Expressions - Constraints

This is a constraint error

A constant is being used which is too large to be represented.

If it is an integer constant, it must be representable within the largest available unsigned type (i.e. unsigned long or unsigned long long depending on whether the option -ex LONGLONG is enabled).

If it is a floating constant, it must be representable within the type of the constant (i.e. float, double or long double, depending on whether the constant has an appropriate suffix). QAC assumes that the maximum values representable in types float, double and long double are the values specifed in IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754-1985) which most implementations adhere to:

  FLT_MAX                 3.40282347E+38F
  DBL_MAX                 1.7976931348623157E+308
  LDBL_MAX                1.7976931348623157E+308L

Notice that the type of a constant is NOT determined by the type of any object to which the constant happens to be assigned.

For example:


/*PRQA S 1264,1265,1278,3120,3121,3198,3210,3211,3408,3447 ++*/
/**************************************/
/* OPTIONS: -ex LONGLONG              */
/**************************************/

extern unsigned long long ux;
extern long double        ld;

void foo(void)
{
    ux = 18446744073709551615ULL;                   /*              */
    ux = 18446744073709551616ULL;                   /* Message 0580 */

    ld = 3.4028234E38F;                             /*              */
    ld = 3.4028235E38F;                             /* Message 0580 */

    ld = 1.797693134E308;                           /*              */
    ld = 1.797693135E308;                           /* Message 0580 */

    ld = 1.797693134E308L;                          /*              */
    ld = 1.797693135E308L;                          /* Message 0580 */
}


MISRA-C:2004 Rules applicable to message 0580:

Rule  1.1  (Required) All code shall conform to ISO/IEC 9899:1990 C programming language, ISO 9899, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2: 1996192


QA·C Source Code Analyser 8.1
MISRA-C:2004 Compliance Module 3.2
© 2012 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents