Related articles |
---|
[4 earlier articles] |
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) |
Re: Integers on 64-bit machines cfc@shell01.TheWorld.com (Chris F Clark) (2007-07-08) |
Re: Integers on 64-bit machines DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-07-09) |
[11 later articles] |
From: | Hans-Peter Diettrich <DrDiettrich1@aol.com> |
Newsgroups: | comp.compilers |
Date: | Fri, 06 Jul 2007 06:22:49 +0200 |
Organization: | Compilers Central |
References: | 07-07-007 07-07-014 07-07-017 |
Keywords: | arithmetic, design |
Posted-Date: | 08 Jul 2007 18:59:04 EDT |
Hans-Peter Diettrich wrote:
> [Defining the range for each variable is one of those ideas that seems
> like a good idea but in practice, programmers don't do it. In Multics
> PL/I programs, all the variables were FIXED BIN(35) because everyone
> knew that was how you got a word variable. On IBM mainframes, they
> were all FIXED BIN(31). -John]
Perhaps somebody can help me with a proper citation: AFAIR Bjarne
Stroustrup (or Wirth?) said about OOP, that it makes a difference
whether a langaage *supports* OOP, or whether it *encourages* to use OOP.
The same for other features of a language. In strictly typed languages,
like Delphi/OPL, it's common practice to use subrange types, along with
enumerated and set types.
Subrange and other types can not only simplify the design and debugging
of a program, they also can lead to faster execution, due to better
optimization criteria for the compiler.
Consider a common situation: the difference between two n-bit values
requires n+1 bits, or overflows can occur when less bits are used for
the result. Using an subrange type of wordsize-n bits, both the user and
the compiler can be sure that a sum or difference cannot produce an
overflow, in computations with full wordsize registers or variables.
A common situation, found in many open source C codes, are comparisons
of signed and unsigned values. The Delphi compiler warns the user, that
the comparison requires to extend the values to the next higher type. I
dunno what a C compiler will do in such cases, but in Delphi I can use
appropriate subrange types to eliminate such conversions.
Now tell me please, how one can prevent overflows or inappropriate or
bloated comparison code, when e.g. only a single integer type is available.
DoDi
Return to the
comp.compilers page.
Search the
comp.compilers archives again.