Download C* User`s Guide

Transcript
C* User Guide
60
But that can't be right: line 47 hasn't been executed yet to set element [2] to 1 for
So why is it set? At this point, we notice another error in our program:we
isprimep.
to 0 in the find primes function. This means that the
forgot to initialize isprimep
parallel variables retain their values from the previous execution of the program (since we
rime_p remains set to 1.
haven't coldbooted the CM), and element [2] of is
We make the required change and try again.
5.9.6
The Final Debugging Session
Here 'is what the code looks like now (the latest revision is in bold):
16384
1. #define MAXIMUMPRIME
2.
3. #define
FALSE
0
4. #define TRUE 1
5. #define FIRSTPRIME
2
34. void find_primes(char:current
35.
36.
*is prime_p)
{
i
char:current is_candidate;
int minimum_prime;
37.
38.
*is_prime_p = FALSE;
39.
40.
is_candidate = (pcoord(O) >= FIRSTPRIME)
? TRUE : FALSE;
41.
42.
43.
do
where(is
46.
iscandidate
= FALSE;
[minimum_prime](*is_prime_p) = TRUE;
47.
49.
{
minimum_prime = <?= pcoord(O);
where(!(pcoord(O) % minimum_prime))
44.
45.
48.
candidate)
}
while(l= iscandidate);
50.
51.
52. main()
53.
{
shape [MAXIMUM_PRIME]s;
54.
55.
char:s is_prime;
56.
int i;
57.
A