title: Confused about C macro expansion and integer arithmetic
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5611724/a-riddle-in-c">A riddle (in C)</a>  </p>
  </blockquote>
  
  
  
  <p>I have a couple of questions regarding the following snippet:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
  int array[] = {23,34,12,17,204,99,16};
  
  int main()
  {
  int d;
  
  for(d=-1;d &lt;= (TOTAL_ELEMENTS-2);d++)
  printf("%d\n",array[d+1]);
  
  return 0;
  }
  </code></pre>
  
  <p>Here the output of the code does not print the array elements as expected. But when I add a typecast of (int) the the macro definition of ELEMENTS  as </p>
  
  <pre><code> #define TOTAL_ELEMENTS (int) (sizeof(array) / sizeof(array[0]))
  </code></pre>
  
  <p>It displays all array elements as expected. </p>
  
  <ul>
  <li>How does this typecast work? </li>
  </ul>
  
  <p>Based on this I have few questions:</p>
  
  <ul>
  <li><p>Does it mean if I have some macro definition as:</p>
  
  <p><code>#define AA  (-64)</code></p></li>
  </ul>
  
  <p>by default in C, all constants defined as macros are equivalent to <strong>signed int</strong>.</p>
  
  <p>If yes, then </p>
  
  <ul>
  <li><p>But if I have to forcibly make some constant defined in a macro behave as an unsigned int is there any constant suffix than I can use (I tried UL, UD neither worked)?</p></li>
  <li><p>How can I define a constant in a macro definition to behave as unsigned int?</p></li>
  </ul>