Having trouble "warning overflow in implicit constant conversion [-Woverflow]"

Hello,

I kept getting this warning “warning overflow in implicit constant conversion [-Woverflow]”. I’m not sure why this is coming up. I’ve tried other larger data types but that just gave me a different warning (warning: large integer implicitly truncated to unsigned type [-Woverflow]). I’ve had also tried macros but the same issue arises. I have exhausted google looking for an answer. The warning did come up on google but none of the answers found matched up with my issue. Posting on here is my last ditch effort before I just silence it with #pragma GCC diagnostic ignored “-Woverflow”

my code is attached.

Thanks in advance,
Magician

crazy_lights.ino (13.8 KB)

1 Like

I'm guessing the author of that code was compiling for a board that uses 32 bit int (Zero, ESP8266, Due, ESP32, etc.) but you're compiling for a board that uses 16 bit ints. Thus the warnings.

MagicianEli:
but that just gave me a different warning (warning: large integer implicitly truncated to unsigned type [-Woverflow]).

Pro tip about warnings: They tell you the exact line number in the code where the warning occurred. When you ask for help on the forum it's useful to post the full output, rather than a fragment. Provided enough information, it's often trivial for us to provide an answer. If you make us download code, install a library, and compile just to get some text you could easily have provided, a lot of forum member won't bother and so you are less likely to get an answer.

Thank you for the Pro Tip. You are right I should have done the snippets of code.

Thank you for going through the trouble of checking out my problem. I very much appreciate it. :slight_smile:

You are definitely right about the “warning: large integer implicitly truncated to unsigned type [-Woverflow]” warning.

I just wish I could figure out the main warning.

For anyone else that would like to help. This is where the “overflow in implicit constant conversion” warning is coming from:

const int ALL_ON_CODE       = 16736925; // Turns on all of  the lights.
const int ALL_OFF_CODE      = 16754775; // Turns off all of the lights.
const int LIGHT_ONE_CODE    = 16738455; // Turns on/off light 1.
const int LIGHT_TWO_CODE    = 16750695; // Turns on/off light 2.
const int LIGHT_THREE_CODE  = 16756815; // Turns on/off light 3.
const int RANDOM_LIGHT_CODE = 16732845; // Truns on/off a random light.
const int CRAZY_LIGHT_CODE  = 16728765; // The lights go crazy.

I’m not sure why it would overflow it’s well within an int’s range.

const int ALL_ON_CODE       = 16736925; // Turns on all of  the lights.

16 bit int?

Hint: Serial.println (sizeof(int));

You are differently right about the "warning: large integer implicitly truncated to unsigned type [-Woverflow]" warning.

Is "differently right" another way of saying "absolutely bang-on"?

1 Like

AWOL:

const int ALL_ON_CODE       = 16736925; // Turns on all of  the lights.

16 bit int?

Hint: Serial.println (sizeof(int));
Is "differently right" another way of saying "absolutely bang-on"?

Right, I was pretty tired when writing that statement. Thank you for your input.

You guys are right, it prints as a two-byte int. So, the problem is with the board not being able to hold the large int.

Thanks for all the help!!!!

You didn't bother saying which board you are using, but I'm sure it can manage a 32 bit value ok. Try using an "unsigned long", but you will have to edit the sketch to upgrade the types elsewhere to avoid truncation.

arduarn:
You didn't bother saying which board you are using, but I'm sure it can manage a 32 bit value ok. Try using an "unsigned long", but you will have to edit the sketch to upgrade the types elsewhere to avoid truncation.

Thanks for your input Arduarn.

The board I am using is a UNO 328P. I was able to fix the warning by using "int32_t" instead of the board's std "int" due to the board having a 16-bit int. I'm sure "unsigned long" would have worked as well.

Thank you for replying and the valuable information. It's very much appreciated.

MagicianEli:
The board I am using is a UNO 328P. I was able to fix the warning by using "int32_t" instead of the board's std "int" due to the board having a 16-bit int. I'm sure "unsigned long" would have worked as well.

Personally I would prefer an unsigned type for storing such a code value (ie. uint32_t), but it shouldn't matter.
In any case, you still need to change other place(s?) in the sketch like:

void IRProcessor(int IRCode){

arduarn:
In any case, you still need to change other place(s?) in the sketch like:

void IRProcessor(int IRCode){

I did thank you.