C integral types [was Re: Semi-OT: Why Kids Can't use Computers]

D. Hugh Redelmeier hugh-pmF8o41NoarQT0dZR+AlfA at public.gmane.org
Thu Aug 15 13:40:10 UTC 2013


| From: James Knott <james.knott-bJEeYj9oJeDQT0dZR+AlfA at public.gmane.org>

|   I had to be careful, due
| to differences in integer size.

That is the nature of C.  If you want to write portable code, you have
to be careful about the width of integral types.  Sadly, the
language gives you inhumane tools for this.

Since your experience, the C Standards have provided headers that let
you select an integral type with a desired number of bits.  But how
does anyone know, for most variables, how many bits they need?

Ignoring that, you kind of know that the following is a monotonically
non-decreasingly wide sequence of types:

	signed char
	short
	int
	long
	long long
	intmaxt_t /* defined in inttypes.h */

Then there are unsigned variants.  And plain char might be signed or
not.

When I first used C, the only char and int existed.  All these others
were accreted over time.

Pascal was much better.  You can use subrange types which let you
specifiy bounds for your integral variables (like array bounds, but
for integers).  Aside from the fact that the bounds had to be known
at compile time, it was quite helpful.

I wrote a lot of code in Sue, an extended subset of Pascal that didn't
even let you declare an integer variable: you always had to use a
subrange.
--
The Toronto Linux Users Group.      Meetings: http://gtalug.org/
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://gtalug.org/wiki/Mailing_lists





More information about the Legacy mailing list