Archive for the ‘C’ Category

h1

When is an int not an int?

December 16, 2010

One but, but only one, use of a type system is to lay out data structures in memory.
(This use is particularly relevant to systems programming and hence to C). So
why does C need a type that is not specific about its size (and int is only required to
be at least 16 bits long) in addition to its gamut of signed and unsigned longs, floats
and doubles.

Int is in fact a speed optimisation: it is whichever format is processed most quickly
in the opinion of a compiler. Thus it is a highly appropriate choice for use in loops,
given the proviso that it cannot be guaranteed to more than 16 bits. Equally, it would
be a poor choice for laying out memory structures that need to be a precise size.

Advertisements