[previous] 2942 [next] Apparent: Result of implicit conversion is only representable in a two's complement implementation.
Conversion to signed

A negative value is being implicitly converted to a signed integer type, but examination of the context indicates that the value is sometimes only representable in this particular type if two's-complement representation is assumed. In practice, two's complement representation is almost universal in modern computers, but other binary representations do exist.

Message 2942 will be generated when

Notice that on a 16 bit architecture:
  1. "32767" is a constant of type int
  2. "32768" is a constant of type long
  3. "-32768" is an expression of type long
  4. "-32767 - 1" is an expression of type int - BUT its value is not guaranteed to be -32768.

For example:


/*PRQA S 282,1278,2017,2983,2986,3120,3199,3203,3227,3408,3602 ++*/
/***************************************************/
/* OPTIONS: -s int=16                              */
/***************************************************/
void foo(signed long slr)
{
    signed int  sir;

    if (slr == -32768L)
    {
    }

    sir = slr;                  /* 2942 3782 */

}

See also:

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