This was raised as part of a bug report for one of the cores I maintain, and I realized I don't understand exactly why this is done. The same idiom is repeated in many libraries around Arduino land.
Wire.h (excerpted)
class TwoWire : public Stream
{
//snip
public:
//snip
uint8_t requestFrom(uint8_t, uint8_t);
//snip
uint8_t requestFrom(int, int);
};
The corresponding implementations, from Wire.cpp:
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
{
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
}
uint8_t TwoWire::requestFrom(int address, int quantity)
{
return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
}
What is the purpose of the requestFrom(int, int); ?
If that weren't there, and someone called requestFrom(a,b); where a and b are of type int (int16_t), wouldn't implicit type conversion convert those int16_t's to uint8_t's, and pipe that request to requestFrom(uint8_t, uint8_t)?
The actual background as to why it was brought to my attention, in the official "mega avr" board package, unlike classic AVR packages, they replaced
uint8_t requestFrom(uint8_t, uint8_t);
with
uint8_t requestFrom(uint8_t, size_t);
This causes certain code which compiles for classic AVRs to fail with errors like this:
C:\Users\lcagl\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.0.2\libraries\Wire\src/Wire.h:75:13: note: candidate 1: uint8_t TwoWire::requestFrom(int, int)
uint8_t requestFrom(int, int);
^~~~~~~~~~~
C:\Users\lcagl\AppData\Local\Arduino15\packages\megaTinyCore\hardware\megaavr\2.0.2\libraries\Wire\src/Wire.h:73:13: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, size_t)
uint8_t requestFrom(uint8_t, size_t);
^~~~~~~~~~~
Unfortunately the person who reported it gave me neither the complete error message nor the code that created it, but the difference between the signatures of the requestFrom() methods is apparent, and I assess that it's likely the cause of this issue... but naturally thinking about that led to my wondering exactly why there are multiple versions of requestFrom() that just typecast the arguments and call another version of requestFrom().