[previous] 2800 [next] Constant: Overflow in signed arithmetic operation.
Overflow and wraparound

This is a constraint error

An arithmetic operation is being conducted on constant operands in a signed integer type and results in overflow. The value cannot be represented. Notice that the limitation here is the size of the signed type in which the operation is performed; not the size of the type to which the resulting value may be assigned. If the size of int is only 16 bits, the first statement in the example code below will result in overflow because evaluation of the multiplication cannot be performed in 16 bits:


/*PRQA S 278,1253,1278,2017,3120,3211,3408,4120 ++*/
/**************************/
/* OPTIONS: -s int=16     */
/**************************/


long x = 30000 * 3;              /* 2800x2 */
long y = 30000 * 3L;             /* OK - multiplication in type long */

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents