title: Microchip C18 - Weird code behavior (maybe extended-mode / non-extended-mode related)
body: <p>I have this weird problem with the Microchip C18 compiler for PIC18F67J60.</p>
  
  <p>I have created a very simple function that should return the index of a Sub-String in a larger String. </p>
  
  <p>I don't know whats wrong, but the behavior seems to be related to wether extended mode is enabled or not. </p>
  
  <p>With Extended-Mode enabled in MPLAB.X I get: </p>
  
  <ul>
  <li>The <code>memcmppgm2ram</code> function returns zero all the time. </li>
  </ul>
  
  <p>With Extended-Mode disabled in MPLAB.X I get: </p>
  
  <ul>
  <li>The value of iterator variable <code>i</code> counts as: <code>0, 1, 3, 7, 15, 21</code></li>
  </ul>
  
  <p>I'm thinking some stack issue or something, because this is really weird. 
  The complete code is shown below.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  char bigString[] = "this is a big string";
  
  unsigned char findSubStr(char *str, const rom char *subStr, unsigned char n, unsigned char m)
  {
      unsigned char i;
  
      for (i=0; i &lt; n-m; i++)
      {
          if(0 == memcmppgm2ram(&amp;str[i], (const far rom void*)subStr, m))
              return i;
      }
      return n; // not found
  }
  
  void main(void)
  {
      char n;
  
      n = findSubStr(bigString, (const rom void*)"big", sizeof(bigString), 3); 
  }
  </code></pre>