Path: utzoo!utgpu!water!watmath!clyde!att!rutgers!uwvax!oddjob!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: "Numerical Recipes in C" is nonportable code Message-ID: <13402@mimsy.UUCP> Date: 6 Sep 88 14:33:56 GMT References: <664@lindy.Stanford.EDU> <6758@megaron.arizona.edu> <718@gtx.com> <867@osupyr.mast.ohio-state.edu> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 35 [me, paraphrased by me:] >An implementation may ABORT ON THE COMPUTATION of an illegal address. In article <867@osupyr.mast.ohio-state.edu> vkr@osupyr.mast.ohio-state.edu (Vidhyanath K. Rao) asks: >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]. On many machines, addresses are unsigned numbers. The domain and range of an unsigned 16-bit number is 0..65535. What is the (mathematical) result of 0 - 1? Answer: -1. Is it in range? No. So what happens? Integer underflow, which on many machines is a trap. You can even do this on a VAX, although there you must first enable the trap (use bispsw or set the appropriate flag in the subroutine entry mask), and then it only fires on integer computations outside the range -2 147 483 648..2 147 483 647; so if (for instance) you were to write main() { char *p; p = (char *)0x7fffffff; asm("bispsw $0x20"); /* PSL_IV */ p++; } This program, when run, aborts with a `floating exception' (SIGFPE). It would be legal for the C compiler to set IV in the entry point of each subroutine, although it would probably break too much code that expects integer overflow/underflow to be ignored, and the code that does C's `unsigned' arithmetic would have to turn it off temporarily. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris