Contiguous Arrays
Doug Gwyn
gwyn at smoke.BRL.MIL
Sun Feb 26 12:08:49 AEST 1989
In article <7309 at killer.DALLAS.TX.US> chasm at killer.DALLAS.TX.US (Charles Marslett) writes:
>This is not necessarily a condemnation of any computer that shows such lack
>of concern for basic mathematics, but I would expect a computer that does
>anything but return equality in the above expression to be broken as a
>mathematical engine. If it is acceptable for addition and subtraction to
>be other than inverse operations (taking into account the possibility of
>an error trap or whatever) the thing you are using cannot support any
>programming language I know of without simulating integer arithmetic with
>some well protected external unit.
First of all, you're wrong. The problem with out-of-range pointer
arithmetic arises from the way that addresses have to be represented
in a segmented architecture: a (segment identifier, offset) pair.
Any arithmetic that would result in an out-of-segment address is simply
illegal; anything could happen, including hardware trap of the illegal
operation. However, in-range address computation presents no problem.
I know of no Algol-like programming language that guarantees the ability
to compute out-of-range pointers even as an intermediate step in a
longer computation, probably because such a guarantee would severely
constrain implementations on some architectures, requiring considerably
less efficient data representations and generated code.
Secondly, no computer fully supports the kind of real-number arithmetic
(including integer arithmetic) that you were taught in school. Instead
of saying that therefore all computers are broken, which is not helpful,
most of us learn how to remain within the range of validity of actual
hardware operations. The proposed C Standard makes explicit what is
guaranteed here, and it does not constrain the programmer any more than
the facts of reality already do. Out-of-range address computation
causes trouble sooner or later; I've seen many examples of that already.
>To make it even more serious, I do not know of any twos-
>complement computer that even has a signed vs. unsigned add instruction.
They are one and the same.
More information about the Comp.lang.c
mailing list