3.3.3. Operations on basic data types

The ARM compilers perform the usual arithmetic conversions set out in relevant sections of the C and C++ standards. The following sections document additional points that relate to arithmetic operations. See also Statements.

Operations on integral types

The following statements apply to operations on the integral types:

  • All signed integer arithmetic uses a two's complement representation.

  • Bitwise operations on signed integral types follow the rules that arise naturally from two's complement representation. No sign extension takes place.

  • Right shifts on signed quantities are arithmetic.

  • Any quantity that specifies the amount of a shift is treated as an unsigned 8-bit value.

  • Any value to be shifted is treated as a 32-bit value.

  • Left shifts of more than 31 give a result of zero.

  • Right shifts of more than 31 give a result of zero from a shift of an unsigned value or positive signed value. They yield –1 from a shift of a negative signed value.

  • The remainder on integer division has the same sign as the divisor.

  • If a value of integral type is truncated to a shorter signed integral type, the result is obtained by discarding an appropriate number of most significant bits. If the original number was too large, positive or negative, for the new type, there is no guarantee that the sign of the result will be the same as the original.

  • A conversion between integral types does not raise an exception.

  • Integer overflow does not raise an exception.

  • Integer division by zero raises a SIGFPE exception.

Operations on floating-point types

The following statements apply to operations on floating-point types:

  • normal IEEE 754 rules apply

  • rounding is to the nearest representable value by default

  • floating-point exceptions are disabled by default.


The IEEE 754 standard for floating-point processing states that the default action to an exception is to proceed without a trap. You can modify floating-point error handling by tailoring the functions and definitions in fenv.h. See Tailoring error signaling, error handling, and program exit and the chapter on floating-point in the ADS Developer Guide.

Pointer subtraction

The following statements apply to all pointers in C. They also apply to pointers, other than pointers to members, in C++:

  • When one pointer is subtracted from another, the difference is obtained as if by the expression:

    ((int)a - (int)b) / (int)sizeof(type pointed to)
  • If the pointers point to objects whose size is one, two, or four bytes, the natural alignment of the object ensures that the division is exact, provided the objects are not packed.

  • For packed or longer types, such as double and struct, both pointers must point to elements of the same array.

Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI 0067D