'Arduino compiler warns about potential conflict in c++ code

I am developing a program in Arduino and until now it works fine but I am getting several warnings of the following type when I compile the code:

Arduino compiler output:

/home/rodolfo/Documents/Arduino/clorofilab/I2C.h: In member function 'void RV8523::countdownNsecTimerA(uint8_t)':
/home/rodolfo/Documents/Arduino/clorofilab/I2C.h:101:11: note: candidate 1: uint8_t I2C::write(int, int, int)
  uint8_t write(int, int, int);
          ^~~~~
/home/rodolfo/Documents/Arduino/clorofilab/I2C.h:100:11: note: candidate 2: uint8_t I2C::write(uint8_t, uint8_t, uint8_t)
  uint8_t write(uint8_t, uint8_t, uint8_t);
          ^~~~~

The code that the warning is referencing to is the following one:

RV8523.cpp

{
  uint8_t writeBytes[3];
  uint8_t returnStatus = 0;

  uint8_t Reg_0Fh, Reg_01h;

  // Disable counter before writting the seconds to be counter
  I2C.read(I2C_ADDR, TimerCLKOUT, 1);                                   // Read actual value of "Timer & CLKOUT" register
  Reg_0Fh = I2C.receive();
  I2C.read(I2C_ADDR, Control_2, 1);                                     // Read actual value of "Control 2" register
  Reg_01h = I2C.receive();
  
  I2C.write(I2C_ADDR, TimerCLKOUT, Reg_0Fh & 0b11111001);                   // Disable counter in "Timer & CLKOUT" register -> TAC[1:0] = 00

  I2C.write(I2C_ADDR, TimerA, Nsec);                                            // Write number of seconds to be counted
  
  (...)
}

I2C.h


uint8_t write(uint8_t, uint8_t);
uint8_t write(int, int);
uint8_t write(uint8_t, uint8_t, uint8_t);
uint8_t write(int, int, int);
uint8_t write(uint8_t, uint8_t, const char *);
uint8_t write(uint8_t, uint8_t, uint16_t);              //Will write 2 bytes
uint8_t write(uint8_t, uint8_t, uint32_t);              //Will write 4 bytes
uint8_t write(uint8_t, uint8_t, uint64_t);              //Will write 8 bytes
uint8_t write(uint8_t, uint8_t, const uint8_t *, uint8_t);

(…)

RV8523.h

(...)
#define I2C_ADDR      (0xD0>>1)
#define TimerA        0x11
#define TimerCLKOUT   0x0F
(...)

After thinking about the problem, my guess is that the compiler doesn't know which "write" function should it use because the defines in "RV8523.h" does not have any type defined but I don't know how to get rid of these warnings in an elegant way...

The code is available in Github if you want to take a deeper look: RV8523 code in Github

I would be greatful if someone could give me a hint. Thanks in advance



Solution 1:[1]

You could include type casts in your header file so the compiler knows which overload to use. For example:

(...)
#define I2C_ADDR      ((uint8_t)(0xD0>>1))
#define TimerA        ((uint8_t)0x11)
#define TimerCLKOUT   ((uint8_t)0x0F)
(...)

or use type casting when you call write:

I2C.write((uint8_t)(I2C_ADDR), (uint8_t)(TimerCLKOUT), (uint8_t)(Reg_0Fh & 0b11111001));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mmixLinus