[net.lang.c] How big is an int, and other oddities.

mwm@ucbtopaz.CC.Berkeley.ARPA (02/28/85)

In article <8715@brl-tgr.ARPA> gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) writes:
>>  If your code needs 34 bit ints ...
>How did you get yourself into this jam?

I was looking for wierd numbers, and the range of interest (which was
actually rather small) was such that the largest integer I had to deal with
was ~5 billion. [Actually, this was a hypothetical case.]

>Ints are only guaranteed to cover the range -32767 to +32767.
>Not even long ints are guaranteed to have 34 bits of dynamic range.

Since the guarantee on range isn't in K&R (or it's well hidden if it is), I
take it's in the ANSI standard?

>I have written a lot of C code and NEVER have had any such
>word length dependencies (other than in explicitly system-dependent
>code that would not make sense to try to port anyway).
>I would be interested in why your code has them.

The (hypothetical) dependency is on magnitude, not length per se. For a
less esoteric number on a more esoteric machine, suppose you needed to deal
with magnitudes around half a million. How do you declare the variables?
Int isn't big enough on most machines, and long isn't big enough in at
least one K&R compiler [this compiler has sizeof(short) == sizeof(int) ==
sizeof(long) == 18 bits. K&R requires only sizeof(short) <= sizeof(int) <=
sizeof(long)].

If the proposal that had started this were in use, you could declare them
as "int20" or thereabouts, thus forcing them into something with at least
20 magnitude bits. If the compiler didn't support ints that big, the
compile of the program would fail on the decleration.

	<mike

hkr4627@acf4.UUCP (Hedley K. J. Rainnie) (03/04/85)

How about making an extension to C a la Algol68 

    long long int x;   /* typdefs would take care of port problems */
    
    short short int y;  /* you wouldn't need to cast unsigned chars for 8
                            bit ints */

    This way the compiler could generate the precision you require.

                    Then of course you could just settle for a 68 compiler
                    and kiss C goodbye....

            Hedley.