[comp.sys.amiga] Int vs. long again

mwm@eris.UUCP (02/22/87)

In article <1494@tekigm2.TEK.COM> phils@tekigm2.UUCP (Philip E Staub) writes:
>Soap box time:

Yup.

>These days, I don't know of many (any?) machines for which a "long" is not
>32 bits and a "short" is not 16 bits.

Crays (yes, mg1a runs on my Cray!). PDP-11's (You may think they're
obsolete, but DEC doesn't - they keep announcing new ones. Also, the
2.10 BSD release for the 11 is in preparation). S-1. QM/C. Probably
lots of others.

>Personally, I avoid the use of the 
>"int" type wherever possible, and use one of the more descriptive
>declarations. This even helps in moving code to such machines as
>pee-cees (argh).

According to the ANSI standard, short & int are at least 16 bits; long is
at least 32. According to K&R, int should be the "natural" size for
the machine, and that short is no longer than int is no longer than
long. For this to be usefull with the ANSI requirements, "natural"
needs to be interpreted as "fastest thing longer than a short."

Given that, shorts should be used for small objects in arrays. Longs
should be used for anything that has to be longer than 16 bits. Int's
should be used for singleton objects that shouldn't get bigger than 16
bits. Like loop counters, small scratch variables, etc.

We all know that there's hardware on which 16 bit ints run faster than
32 bit ones. I've worked with hardware (very, very popular hardware,
at that!) on which 16 bit ints run slower than 32 bit ones (you have
to do a half-word extract on them).

It's for machines like that that you use int.

	<mike



But I'll survive, no you won't catch me,		Mike Meyer
I'll resist the urge that is tempting me,		ucbvax!mwm
I'll avert my eyes, keep you off my knee,		mwm@berkeley.edu
But it feels so good when you talk to me.		mwm@ucbjade.BITNET