Integer overflow: Difference between revisions

Content deleted Content added
MacGyverMagic (talk | contribs)
m fmt lead
No edit summary
Line 6:
The size of the number able to be stored (and the size of the possible result) is based on the [[register width]] of the processor on which the code is to be executed. Common binary sizes for integers include 8 bits, 16 bits, 32 bits (the most common width as of 2005), 64 bits, and 128 bits.
 
Since a math operation may give a result larger than the available register width, an error condition may result. The [[ISO]] [[C99 standard]] (also known as printed standard ISO/IEC 9899:1999 (E)) defines the behavior of software compilers. However, this standard defines the appropriate behavior for the integer overflow case to be "undefined behavior." Different compilers may treat this error condition in various ways, including ignoring the overflow completely, and simply returning the smallsmallest or largest portion of the result (depending on whether the system is [[little endian]]) or large ([[big endian]]) portion of the result.
 
This can also occur if the processor has a register width capable of storing the result, but the result is stored into a [[variable]] that is too small to store the entire result.