title: How can I fix warnings like: "comparison between signed and unsigned"?
body: <p>I have been advised to use the following options with GCC, as it helps to avoid a lot of common errors. It turns on a bunch of warnings and <code>-Werror</code> turns them into errors.</p>
  
  <pre><code>gcc -pedantic -W -Wall -Wextra -Wshadow -Wstrict-overflow=5 -Wwrite-strings -std=c99 -Werror
  </code></pre>
  
  <p>Given the following test code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(void)
  {
      int arr[8]={0,10,20,30,40,50,60,70};
      int x;
  
      printf("sizeof(arr): %d\n", sizeof(arr));
      printf("sizeof(int): %d\n", sizeof(int));
  
      for(x = 0; x &lt; sizeof(arr)/sizeof(int); x++)
      {
          printf("%d\n",arr[x]);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>test.c:11: error: comparison between signed and unsigned
  </code></pre>
  
  <p>I know that one way I can fix this is turning off the warnings, but they haven't made me use these settings to turn them off in the end.</p>
  
  <p>Another way is to cast the stuff, but I have been told that casting is deprecated.</p>
  
  <p>Also, I could make x into an <code>unsigned int</code>:</p>
  
  <pre><code>unsigned x;
  </code></pre>
  
  <p>But it doesn't solve the general problem when I have to compare signed values with unsigned values using these compiler options. Is there an cleaner way instead of casting?</p>