Related articles |
---|
[13 earlier articles] |
Re: New Book: The School of Niklaus Wirth gdemont@my-deja.com (2000-11-16) |
Re: New Book: The School of Niklaus Wirth jerrold.leichter@smarts.com (Jerry Leichter) (2000-11-17) |
Re: New Book: The School of Niklaus Wirth fjh@cs.mu.OZ.AU (2000-11-19) |
Re: New Book: The School of Niklaus Wirth vbdis@aol.com (2000-11-19) |
Re: New Book: The School of Niklaus Wirth jerrold.leichter@smarts.com (Jerry Leichter) (2000-11-21) |
Re: New Book: The School of Niklaus Wirth gdemont@my-deja.com (2000-11-22) |
Re: New Book: The School of Niklaus Wirth nr@labrador.eecs.harvard.edu (2000-11-30) |
From: | nr@labrador.eecs.harvard.edu (Norman Ramsey) |
Newsgroups: | comp.compilers |
Date: | 30 Nov 2000 12:09:50 -0500 |
Organization: | Harvard University |
References: | 00-11-046 00-11-082 00-11-120 00-11-122 |
Keywords: | modula, Pascal, types |
Posted-Date: | 30 Nov 2000 12:09:50 EST |
Jerry Leichter <jerrold.leichter@smarts.com> wrote:
>On the other hand, Modula-3 does not have an unsigned type - and I think
>with good reason.
>
>There are two reasons for wanting an unsigned type:
> (1) ...
> (2) To implement "modulo arithmetic". Unsigned ints typically
> (and, by standard in C/C++) the mathematical properties
> of arithmetic mod 2^k. There are times when this is
> useful.
>...you have to ask
>the question: Do we really need a *type* for this - or do we just want
>the operations? The latter is the approach Modula-3 took:
This choice bit me badly, multiple times. The problem was that
although I could write Word.T and Word.Plus all I wanted, I repeatedly
made the mistake of ``accidentally'' applying signed-integer
operations to 32-bit addresses represented as Word.T. I would have
been *very* grateful for a type system that distinguished the two
types, so as to catch these mistakes at compile time. Especially as a
lot of the 32-bit addresses got used in unsafe code :-)
N.B. I am *not* arguing for overloading +. I am happy to write
Word.Plus. What I really want is a type that won't allow me to use
signed operations by mistake.
>The *big* advantage to this approach is that it eliminates all kinds
>of issues about how signed and unsigned integers should work when they
>"meet across an operator".
Yes, this is quite useful---but it would have been even better if the
M3 designers had distinguished the two *types*, and not only the
*operations*.
--
Norman Ramsey
http://www.eecs.harvard.edu/~nr
Return to the
comp.compilers page.
Search the
comp.compilers archives again.