[previous] 3103 [next] Result of signed division or remainder operation may be implementation defined.
Arithmetic type - Operations REFERENCE - ISO:C90-6.3.5 Multiplicative Operators - Semantics

A division ('/') or remainder ('%') operation is being performed in a signed integer type and the result may be implementation-defined.

Message 3103 is generated for an integer division or remainder operation in a signed type where:

A signed integer division or remainder operation in which one operand is positive and the other is negative may be performed in one of two ways:
  1. The division will round towards zero and any non-zero remainder will be a negative value
  2. The division will round away from zero and any non-zero remainder will be a positive value

In the ISO:C99 standard the first approach is always used. In the ISO:C90 standard either approach may be used - the result is implementation defined.

For example:


/*PRQA S 3120,3198,3408,3447 ++*/

extern int r;
extern int si;

extern void foo(void)
{
    r = -7 / 4;                  /* Message 3103 */     /* Result is -1 in C99 but may be -2 in C90 */
    r = -7 % 4;                  /* Message 3103 */     /* Result is -3 in C99 but may be  1 in C90 */
    si = si / r;                 /* Message 3103 */
}

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