Note that there are some explanatory texts on larger screens.

plurals
  1. POC Array change causing variable modification
    primarykey
    data
    text
    <p>I am trying to modify a value in an array using the C programming language and I seem to be hitting a blank wall with this seemingly easy operation. Please see code snippet below:</p> <pre><code>while(1) { printf("Current prime candidate is %i\n",nextPrimeCandidate); int innerSieve;//=2; int currentPrimeCandidate=0; for (innerSieve=2;innerSieve&lt;SIEVELIMIT;innerSieve++) { currentPrimeCandidate = nextPrimeCandidate * innerSieve; //printf("Inner Sieve is b4 funny place %i,%i\n",innerSieve,currentPrimeCandidate); //initArray[currentPrimeCandidate]=5; //VERY UNIQUE LINE myArray[currentPrimeCandidate] = 0; //printf("Inner Sieve after funny place is %i,%i \n",innerSieve,currentPrimeCandidate); } nextPrimeCandidate=getNextPrimeCandidate(myArray,++nextPrimeCandidate); if ((nextPrimeCandidate^2) &gt; SIEVELIMIT ) break; } </code></pre> <p>The problem is with the line highlighted with the <code>VERY UNIQUE LINE</code> comment. For some reason, when the innerSieve variable reaches 33 and gets to that line, it sets the contents of the innerSieve variable to the value of that line ( which currently is 0) and basically forces the loop into an infinite loop( the <code>SIEVELIMIT</code> variable is set at 50). It seems that there is some funny stuff going on in the registers when I checked using the Eclipse Debug facility but I am not too sure what I should be looking for.</p> <p>If you need the whole code listing, this can be provided.( with a particular variable which is not yet initialised in the code being initialised at the precise point that the innerSieve variable hits 32)</p> <p>Any help will be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload