title: C: A cure for the warning: integer overflow in expression?
body: <p>I am trying to organise my UART library and prettify it a little bit by adding some #define s so I can customize it later without having to dig deeply into the code, but I can't seem to get the following bit of code working:</p>
  <pre><code>#define FOSC        8000000
  #define BAUDRATE    9600
  #define BRGVAL      (FOSC/2)/(16*BAUDRATE)-1
  
  void uart_init(){
     U1BRG = BRGVAL;
  }
  </code></pre>
  <p>After the calculation BRGVAL becomes 25.0416667, and because it is not an integer I get the following warning for it when I assign that into U1BRG:</p>
  <blockquote>
  <p>UART.c: In function 'uart_init':</p>
  <p>UART.c:24: warning: integer overflow in expression</p>
  </blockquote>
  <p>...and the code simply does not work on target hardware. (If I manually put in U1BRG = 25 it works like a charm though)</p>
  <p>Is there any way to typecast that constant into an integer to make the compiler happy?</p>
  <p>Many Thanks,
  Hamza.</p>