Does the compiler adjust data type to fit function definition?

Well, let me give an example.

I'm using the IRremote library with a Nano, and it's a Sharp TV. The library includes this function in its ir_Sharp.cpp file:

void IRsend::sendSharpRaw (unsigned long data, int nbits)

But it turns out that for this model the nunber of bits is always 15, and all the codes look like 0x4572. So an unsigned int would work fine for any valid code. So I've defined all the codes as unsigned ints, and my calling function looks like this:

void sendTV(unsigned int Output) {
irsend.sendSharpRaw(Output,15);
delay(Interval);
}

And it compiles with no warnings. So it appears the compiler is automatically converting what I'm supplying to what the library is looking for. But I wonder how much I can depend on this in other situations. Are there rules saying when this works and when it doesn't? Or is it just always bad practice?

If you have a few minutes, why don't you write a test program and see what happens?

Paul

There are C / C++ rules that require the compiler to make some but not all conversions.

you can try adding -Wall and -Werror

from the Arduino IDE, you can adjust compiler warnings under File->preferences

i believe checking function argument types was one of the first reasons Bell Labs started using C++

The compiler will try to convert your values to match a function. If it can't find a conversion that will make a match OR it finds two different conversions that that match two different versions of the function, you will get a compile error.