How big is an int, and other oddities.

mwm at ucbtopaz.CC.Berkeley.ARPA mwm at ucbtopaz.CC.Berkeley.ARPA
Fri Mar 1 05:56:08 AEST 1985


In article <8715 at brl-tgr.ARPA> gwyn at 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



More information about the Comp.lang.c mailing list