Uses of "short" ?

tp at ndm20 tp at ndm20
Thu Sep 19 00:24:00 AEST 1985


>I doubt we disagree fundamentally; I just think you are stating the case too
>strongly.  My goal is to introduce environment dependencies only as needed.
>I nevertheless believe, for instance, that when Internet protocol specifies
>that the header checksum is a 16-bit 2's-complement number, it is wise to
>comply, if you want the packets to fly properly.

But what type is that in C.  On a Harris H-series machine, a short is
24 bits, as is an int.  A long is  48 bits.   Obviously  this kind of
code is machine dependent.  I believe that the point Guy is trying to
make is that you CAN NOT assume that  a short  is 16  bits on *every*
machine, because it isn't, so you should recognize that  what you are
doing is machine dependent, no matter HOW you code it  in C.   If the
exact number of bits is mandated, it is a machine dependence how that
will be handled.  If it is not, then we should deal with abstractions
to produce more portable code.  

I always use the guideline that if a number is  less than  16K, I use
short, and if it is known to be greater than that I use long.  If the
range of values is not well known, or space efficiency is not a great
concern, I use int, as that is presumably the  most efficient integer
type.  These aren't the best guidelines in the  world, and  I am open
to better suggestions.   It  would be  nice to  be able  to declare a
value  range  and  let the  compiler pick  the type  based on machine
characteristics (a la Pascal).

Terry Poot
Nathan D. Maier Consulting Engineers
(214)739-4741
Usenet: ...!{allegra|ihnp4}!convex!smu!ndm20!tp
CSNET:  ndm20!tp at smu
ARPA:   ndm20!tp%smu at csnet-relay.ARPA



More information about the Comp.lang.c mailing list