Problem compiling a 31 bit 0b011...011 value

I am using 1.8.19 compiler for a uno and a beginner with C++!!

The following code compiles with an error at " TestData[6]" and onwards
" TestData[5]" line compiles ok.
The snippet compiles ok with a normal C++ compiler.

The error is "warning: overflow in implicit constant conversion [-Woverflow]

void setup() {
  // put your setup code here, to run once:

}

const int ControlDataMaxLen = 50;
  int ControlData[51];
  int ControlDataLen = 50;

  int TestData[50];
  int TestDataLen = 0;





void loop() 
  {
  TestData[0] =  12;             
  TestData[1] =  30;             
  TestData[2] =  20;            
  TestData[3] =  0;              
  TestData[4] =  0;              
  TestData[5] =  0b0000000000000000000000010000001;     
  TestData[6] =  0b0000000001000000000000000100010;      
  TestData[7] =  0b0000000001000000000000010000001;     
  TestData[8] =  0b0000000001000000000000000100101;     
  TestData[9] =  0b0000000001000000000000010000001;     
  TestData[10]=  0b0000000001000000000000010001010;     
  TestData[11] = 0b0000000001000000000100100100010;     
  TestData[12] = 0b0000000000000000000000000000000;     
  }
  1. What is the size of int?

The array is defined as "int" so I assumed 32 bits.

Arduino UNO R3?

Also constant must be defined as long.

The size of int depends on the architecture you are using...

Serial.println(sizeof(int));

No - a Freenove Control BoardV4 but programmed as a "uno" as recommended.

It seems to be ATmega328P MCU, so the int is 16 bit.

Budvar 10 - Many thanks - I will try this now.

Problem Solved - thank you.

In C/C++ the int size is ambiguous like @Rintin wrote. You can use int32_t instead.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.