Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>The processor doesn't need to "expand" a value to work with it. It just pads the unused spaces with zeroes and ignores them when performing calculations. So, actually, it is faster to operate on a <code>short int</code> than a <code>long int</code>, although with today's fast CPUs it is very hard to notice even a bit of difference (pun intended).</p></li> <li><p>The machine doesn't really convert. When changing the size of a value, it either pads zeroes to the left or totally ignores extra bits to the left that won't fit in the target memory region.</p></li> <li><p>No, and this is usually the reason people use <code>short int</code> values for purposes where the range of a <code>long int</code> just isn't needed. The memory allocated is different for each length of <code>int</code>, like a <code>short int</code> takes up fewer bits of memory than a <code>long int</code>. One of the steps in optimization is to change <code>long int</code> values to <code>short int</code> values when the range does not exceed that of a <code>short int</code>, meaning that the value would never use the extra bits allocated with a <code>long int</code>. The memory saved from such an optimization can actually be quite significant when dealing with a lot of elements in arrays or a lot of objects of the same <code>struct</code> or <code>class</code>.</p></li> </ol> <p>Different <code>int</code> sizes are stored with different amounts of bits in both the RAM and the internal processor cache. This is also true of <code>float</code>, <code>double</code>, and <code>long double</code>, although <code>long double</code> is mainly for 64-bit systems and most compilers just ignore the <code>long</code> if running on 32-bit machines because a 64-bit value in a 32-bit accumulator &amp; ALU will be 'mowed down' during any calculation and would likely never receive anything but zeros for the first 32 bits.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload