HARRIS FLAME Re: SHORT vs. INT
Robert Clark
robert at fortune.UUCP
Sat Sep 21 03:20:46 AEST 1985
In article <2803 at sun.uucp> (Guy Harris) writes:
>> >People who use the C language should be sufficiently expert that they
>> >understand that "long" and "short" should not be selected in favor of "int"
>> >only if they are of different sizes on the machine you're coding on.
>>
>> But I can't quite fiqure out what you mean here. Does it mean that is
>> if 'short' 'int' and 'long' are the same size then I should choose
>> something other than 'int'?
>
>You did figure out what I meant - that is exactly what I mean! If you want
>to have a variable that can hold values outside the range -32767 to 32767,
>use "long", regardless of whether something else just might happen to work.
>It won't work on other machines, and unless you can guarantee that the code
>will *never* be run on another machine, you shouldn't do it.
If one is very concerned about portability to other-wordlength machines, why
not use typdefs like:
typedef int bit16;
typedef long bit32;
Then make all your declarations as bit16, bit32, etc. Then when you want to
port to a machine with 7 bit shorts, 14 bit ints and 35 bit longs :-), just
change all the typedefs to "typedef long bit16", etc....
I can see not liking the way this would make the code look, but it would
certainly help with portability, and could make a big difference in final
process size if there are large arrays, etc.
Robert Clark
UUCP: {sri-unix, amd, hpda, harpo, ihnp4, allegra}!fortune!robert
DDD: (415) 594-2822
USPS: Fortune Systems Corp, 101 Twin Dolphin Pkwy, Redwood Shores, CA 94065
More information about the Comp.lang.c
mailing list