Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.lang.c Subject: Re: "Numerical Recipes in C" is nonportable code Message-ID: <656@proxftl.UUCP> Date: 29 Aug 88 06:19:02 GMT References: <664@lindy.Stanford.EDU> <6758@megaron.arizona.edu> <718@gtx.com> <13258@mimsy.UUCP> <531@accelerator.eng.ohio-state.edu> Reply-To: bill@proxftl.UUCP (T. William Wells) Organization: Proximity Technology, Ft. Lauderdale Lines: 49 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <531@accelerator.eng.ohio-state.edu> rob@kaa.eng.ohio-state.edu (Rob Carriere) writes: : In article <13258@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: : > [ still on the b = malloc( foo ); bb = b - 1; code in NumRecipes ] : >Such an implementation will ABORT ON THE COMPUTATION `b - 1', : >possibly (indeed, preferably) at compile time. And it is legal! : : So the standard says, they tell me. It is also one the more flagrant : violations of the Principle of Least Astonishment I've seen in a : while. Actually, on a segmented architecture I might be astonished if it *didn't* bomb. The principle is rather subjective I'm afraid. : In fact, while we're at it, it would seem to violate the idea : that you give the programmer all the rope she asks for, because she : just might be needing it to pull herself out of a bog. Note that the standard does *not* say that you can't do this, it just says that it is nonportable. So, unless this bog is a portable bog, she (Ugh. I prefer s/h/it for a neutered pronoun :-) won't need a portable rope! : Gentlemen : system programmers, surely you too have algorithms that are more : accurately expressed with arrays from other than base zero? Well, actually, no. One of the characteristics of being *very* experienced with a language is that you tend to think of solutions in terms of what that language most easily supplies. Hmmmm. Now that I think about it, I do seem to recall some Shell sort where a zero base made the code more complex. However, since there *is* a portable way to do this (if you don't mind the syntax), I'll show it. func() { int foo_array[SIZE][SIZE]; #define foo(n,m) (foo_array[(n)-1][(m)-1]) ... } Ugly, but it works. And it can be used to make the NR programs portable. --- Bill novavax!proxftl!bill