Noalias trivia question
hutchson at convex.UUCP
hutchson at convex.UUCP
Thu Jun 23 08:00:00 AEST 1988
For a less contrived example:
for (i=n; i; i--) a[i]=i; /* each number in (i:n) occurs once in a. */
shuffle(a); /* randomly or not--doesn't matter. */
...
Now, the programmer knows full well that i!=j implies a[i]!=a[j].
But try explaining that to your favorite optimizer. Better hope it
understands second-order logic. If you really want a challenge, try letting
it figure it out for itself. Remember that this property of a is not
created, but is maintained, by "shuffle".
Such code would be found somewhere in, say, a blackjack simulation. I suspect
that properties of permutations of arrays might be useful in more productive
programs also.
More information about the Comp.lang.c
mailing list