title: C language: #DEFINEd value messes up 8-bit multiplication. Why?
body: <p>I have the following C code:</p>
  
  <pre><code>#define PRR_SCALE 255
  ...
  uint8_t a = 3;
  uint8_t b = 4;
  uint8_t prr;
  prr = (PRR_SCALE * a) / b;
  printf("prr: %u\n", prr);
  </code></pre>
  
  <p>If I compile this (using an msp430 platform compiler, for an small embedded OS called <a href="http://www.sics.se/contiki/" rel="nofollow noreferrer">contiki</a>) the result is 0 while I expected 191.
  (uint8_t is typedef'ed as an unsigned char)</p>
  
  <p>If I change it to:</p>
  
  <pre><code>uint8_t a = 3;
  uint8_t b = 4;
  uint8_t c = 255;
  uint8_t prr;
  prr = (c * a) / b;
  printf("prr: %u\n", prr);
  </code></pre>
  
  <p>it works out correctly and prints 191.</p>
  
  <p>Compiling a simple version of this 'normally' using gcc on an Ubuntu box prints the correct value in both cases.</p>
  
  <p>I am not exactly sure why this is. I could circumvent it by assigning the DEFINEd value to a variable beforehand, but I'd rather not do that.</p>
  
  <p>Does anybody know why this is? Perhaps with a link to some more information about this?</p>