"Numerical Recipes in C" is nonportable code
T. William Wells
bill at proxftl.UUCP
Mon Aug 29 16:19:02 AEST 1988
In article <531 at accelerator.eng.ohio-state.edu> rob at kaa.eng.ohio-state.edu (Rob Carriere) writes:
: In article <13258 at mimsy.UUCP> chris at 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
More information about the Comp.lang.c
mailing list