Re: Integers on 64-bit machines

Robert A Duff <bobduff@shell01.TheWorld.com>
Thu, 05 Jul 2007 20:50:03 -0400

          From comp.compilers

Related articles
[2 earlier articles]
Re: Integers on 64-bit machines marcov@stack.nl (Marco van de Voort) (2007-07-04)
Re: Integers on 64-bit machines emailamit@gmail.com (Amit Gupta) (2007-07-05)
Re: Integers on 64-bit machines DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-05)
Re: Integers on 64-bit machines anton@mips.complang.tuwien.ac.at (2007-07-05)
Re: Integers on 64-bit machines mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-07-05)
Re: Integers on 64-bit machines gah@ugcs.caltech.edu (glen herrmannsfeldt) (2007-07-05)
Re: Integers on 64-bit machines bobduff@shell01.TheWorld.com (Robert A Duff) (2007-07-05)
Re: Integers on 64-bit machines marcov@stack.nl (Marco van de Voort) (2007-07-06)
Re: Integers on 64-bit machines DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-06)
Re: Integers on 64-bit machines DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-06)
Re: Integers on 64-bit machines DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-06)
Re: Integers on 64-bit machines anton@mips.complang.tuwien.ac.at (2007-07-06)
Re: Integers on 64-bit machines marcov@stack.nl (Marco van de Voort) (2007-07-08)
[13 later articles]
| List of all articles for this month |

From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Thu, 05 Jul 2007 20:50:03 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 07-07-007 07-07-014 07-07-017 07-07-022
Keywords: types
Posted-Date: 06 Jul 2007 01:49:31 EDT

Our esteemed moderator writes:


> [The problem isn't that it's a variable rather than a type, the problem is
> that programmers aren't very good at predicting the range of values
> that a variable can take, so they won't try. If you force them to do so,
> as PL/I does, they'll pick a size that works reasonably consistently and
> always use that. -John]


My experience is different, for languages that support ranges
(as opposed to bit-counts) -- Pascal, Modula-2, and Ada, for example.
Programmers in those languages use subrange types quite heavily.


Sometimes the range is something like 1..Max_Int, where as you say, the
programmer couldn't predict the upper bound very well. But even
in that case, the lower bound is clear. Other times, more meaningful
upper bounds are used. 1..31 for day-within-month, for example.


In Ada, you can say:


        type Foo is range 1..1_000_000;
        subtype Bar is Foo'Base range 1..Foo'Base'Last;


which means that Bar has a range whose lower bound is 1,
and whose upper bound is at least a million, but chosen
by the compiler to match the hardware (perhaps 2**31-1).


Subranges of enumeration types and character types also
make sense. (A character type is an enumeration type,
in Ada.) And for floating-point and fixed-point types.


In Lisp, Smalltalk, etc, the programmer who is not "very good at
predicting the range of values" uses bignums, at the cost of some
efficiency. I'd like to get the best of both worlds.


Anyway, if programmers (who supposedly know their problem domain)
can't choose ranges properly, how on Earth can the language designer
or the compiler writer (who knows the hardware, but has no idea about
the problem being solved)? And what is the programmer supposed to do
with a type called "int" or "Integer" that is a small subset of the
integers, whose bounds are based on the whim of the compiler writer?
The programmer who wants to write portable code, I mean.


- Bob


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.