| |||
| Home > C and C++ Implementation Details > C and C++ implementation details > Operations on basic data types | |||
The ARM compiler performs the usual arithmetic conversions set out in relevant sections of the ISO C99 and ISO C++ standards. The following subsections describe additional points that relate to arithmetic operations.
See also Expression evaluation.
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.
For values of type int,
Shifts outside the range 0 to 127 are undefined.
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.
For values of type long long, shifts outside the range 0 to 63 are undefined.
The remainder on integer division has the same sign as the numerator, as mandated by the ISO C99 standard.
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 is too large, positive or negative, for the new type, there is no guarantee that the sign of the result is going to 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 returns zero by default.
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.
Also, see --fpmode=model.
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 Modification
of C library functions for error signaling, error handling, and
program exit in Using ARM® C and C++ Libraries and
Floating-Point Support for more information.
The following statements apply to all pointers in C. They also apply to pointers in C++, other than pointers to members:
When one pointer is subtracted from another, the difference is the result of the expression:
((int)a - (int)b) / (int)sizeof(type pointed to)
If the pointers point to objects whose alignment is the same as their size, this alignment ensures that division is exact.
If the pointers point to objects whose alignment is less than their size, such as packed types and most structs, both pointers must point to elements of the same array.