"Numerical Recipes in C" is nonportable code

Craig Jackson dricej at drilex.UUCP
Mon Sep 5 09:13:56 AEST 1988


In article <867 at osupyr.mast.ohio-state.edu> vkr at osupyr.mast.ohio-state.edu (Vidhyanath K. Rao) writes:
>In article <8395 at smoke.ARPA>, gwyn at smoke.ARPA (Doug Gwyn ) writes:
>> [From way past]
>    Such an implementation will ABORT ON THE COMPUTATION `b - 1',
>> That is not an X3J11 invention, just an acknowledgement of the
>> way the world is.  (For example, segmented architectures.)
>
>But why should it abort? If the address is sr:0, (sr = segment register)
>subtract 1 to get (sr-1):ffff [or whatever number of 'f's]. Memory
>protection, it seems to me, should not notice attempts to compute addresses
>but only attempts to access forbidden addresses. 

There exist machines whose protection philosophy is to prevent you from
even thinking something illegal.  In particular, on the Unisys A-series,
the compiler must implement all memory addressing protection--there is
no kernel/user state protection on memory.*  A program cannot be allowed
to form an invalid address, as there is nothing to stop it from using it,
and nothing in the hardware to stop you from stomping on another user
if you do.  Therefore, the compiler and the operating system would be
written so as to cause an interrupt if computing 'b - 1' were attempted.
The ANSI rules were written to allow C to be implemented on such an
architecture.

Note that there is no C compiler for the A-series today, although one is
rumored.  The rumors say that arrays and pointers will not be implemented
this way, however.  In order to get around some other problems, and to allow
more old programs to run, a linear-address space machine will be simulated,
using a large array.  (Arrays are hardware concepts on the A-series.)

>Of course, this approach levies heavy penalities on segmented architecutres.

On some architectures, it may be an infinite penalty--C could not be
implemented.  Or maybe only by simulating a more PDP-11-like machine
(as discussed above).

>If you are using the 'small' model (in the 8088 meaning of the word), 
>sr:0 - 1 = sr:ffff. Now you got to worry about the model. But doesn't the
>philosophy of C say 'programmer knows best'. If you want to diddle with
>segmented architectures, you got to put up with headaches.

You sometimes have to, in order to get some benefits (like having your
OS written in a really high-level language, with no assembler, etc.)

>So what am I missing?

A broad education in the corners of the computer architecture world.

>-Nath
>vkr at osupyr.mast.ohio-state.edu

* Note that putting the protection in the compiler was also an idea
of Per Brinch-Hansen's in the 1970s, with Concurrent Pascal.  Burroughs
had been doing it for many years, even then.
-- 
Craig Jackson
UUCP: {harvard!axiom,linus!axiom,ll-xn}!drilex!dricej
BIX:  cjackson



More information about the Comp.lang.c mailing list