Next: , Previous: , Up: Particular Modules   [Contents][Index]

17.7 Integer Properties

The intprops module consists of an include file <intprops.h> that defines several macros useful for testing properties of integer types.

Integer overflow is a common source of problems in programs written in C and other languages. In some cases, such as signed integer arithmetic in C programs, the resulting behavior is undefined, and practical platforms do not always behave as if integers wrap around reliably. In other cases, such as unsigned integer arithmetic in C, the resulting behavior is well-defined, but programs may still misbehave badly after overflow occurs.

Many techniques have been proposed to attack these problems. These include precondition testing, wraparound behavior where signed integer arithmetic is guaranteed to be modular, saturation semantics where overflow reliably yields an extreme value, undefined behavior sanitizers where overflow is guaranteed to trap, and various static analysis techniques.

Gnulib supports wraparound arithmetic and precondition testing, as these are relatively easy to support portably and efficiently. There are two families of precondition tests: the first, for integer types, is easier to use, while the second, for integer ranges, has a simple and straightforward portable implementation.

Like other Gnulib modules, the implementation of the intprops module assumes that integers use a two’s complement representation, but it does not assume that signed integer arithmetic wraps around. See Other portability assumptions made by Gnulib.

Next: Static inline functions, Previous: Non-returning Functions, Up: Particular Modules   [Contents][Index]