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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: