pic18, xc8, v2.05, arithmetic overflow in constant expression

Thread Starter

bug13

Joined Feb 13, 2012
2,002
It must be an XC8 thingy.

I can do these with no warnings on IAR Embedded Workbench and Atollic TrueSTUDIO.

SPBRG = 416 & 0xFF;
SPBRGH = 416 >> 8;
No warning in Code::Blocks with mingw32-gcc as well.

On a side note, I am playing with an stm32f303k8 in TrueSTUDIO, I love the CubeMX which can generate the driver for me and set up the clock. But I find that the uart driver generated by CubeMX is bit weird (how it handle interrupt) and I think it's not suitable for embedded system (at least not what I use to anyway).

So I want to write my own uart/usart interrupt driver, but I don't seem to find an user guide/manual for the arm-gcc compiler use in TrueSTUDIO. I have no idea how to hook my own uart/usart interrupt code, any pointer for me?? I am totally new to ARM
 

Thread Starter

bug13

Joined Feb 13, 2012
2,002
These are not the same... You do know that don't you... while you have the compiler up..
SPBRG = (uint8_t)416 & 0xFF; <-- does this give a warning?
Since I am at it on this post (not trying to argue or find out why) did a quick test, this still give me the same warning
 
These are not the same... You do know that don't you... while you have the compiler up..
SPBRG = (uint8_t)416 & 0xFF; <-- does this give a warning?
WHAT are not the same? Am I supposed to read your mind?

Are you asking if I know whether or not the two statements below are the same?
SPBRG = 416 & 0xFF;
SPBRGH = 416 >> 8;
 
while you have the compiler up..
SPBRG = (uint8_t)416 & 0xFF; <-- does this give a warning?
C:
#include <xc.h>
#include <stdint.h>

void main(void) {
  uint8_t SPBRG;
  SPBRG = (uint8_t)416 & 0xFF;
  return;
}
main.c:7:: warning: (751) arithmetic overflow in constant expression

Yes, it gives a warning. Also tested by OP in post #83

In addition, in my post #69
SPBRG=(uint8_t) (416 & 0x00ff ); // WARN
SPBRG=(uint8_t) (416 & 0x0f); // WARN

What is your thinking?
 

MrChips

Joined Oct 2, 2009
30,824
No warning in Code::Blocks with mingw32-gcc as well.

On a side note, I am playing with an stm32f303k8 in TrueSTUDIO, I love the CubeMX which can generate the driver for me and set up the clock. But I find that the uart driver generated by CubeMX is bit weird (how it handle interrupt) and I think it's not suitable for embedded system (at least not what I use to anyway).

So I want to write my own uart/usart interrupt driver, but I don't seem to find an user guide/manual for the arm-gcc compiler use in TrueSTUDIO. I have no idea how to hook my own uart/usart interrupt code, any pointer for me?? I am totally new to ARM
Sure, I can show you how to do that. You can start a new thread on STM32 UART interrupts.
 
I'm thinking that the constant int cannot be cast!! even though the syntax is correct...XC8 seems to have "another" bug..
Well, it can be cast but as previously noted, when casting it to an int8_t, ...
When SPBRG is declared as uint8_t...
and SPBRG=416, you get a legitimate warning...
warning: implicit conversion from 'int' to 'uint8_t' (aka 'unsigned char') changes value from 416 to 160 [-Wconstant-conversion]
SPBRG=416;
and yes, that post was not a cast, but it illustrates the kind of warning that I would have expected when it is cast - 416 to uint8_t

But, in the cases that we have been exploring (maybe for too long), it decides on giving you a different warning whether you want it or not and whether you are requesting that it do something before casting that will reduce it to the size of an int8_t. That is how I am seeing it currently anyways.
 
Last edited:
Top