strange behavior of overloaded function

Hi, i have a function that has no return value and can take either a boolean or int value:

void f(boolean p);
void f(int p);

so i expect to call the appropriate function when i pass the boolean or int parameter, yet when i pass the function "true":

f(true);

the f(int p) is called instead of f(boolean t)

i can correct it by calling the function with:

f((boolean)true);

but i think it's ugly, and wrong :slight_smile:

Any solution to that problem? Is it a problem at all, or is it expected behavior?

The symbol true is #defined into existence. It has a numeric value associated with it. So, true is an int, as is false.

You could do something like this:

boolean stat = true;
f(stat);

umm... is boolean then a byte long or is it shorter(longer)?
if it isn't really a single bit, what's the point of having it?

in wiring.h:

#define true 0x1
#define false 0x0

so it really doesn't have a length per se.

ok, i found in reference answer to my question, boolean is one byte long, so i can just use one function that takes a byte, or use your approach with a variable

tnx for quick answers

, boolean is one byte long, so i can just use one function that takes a byte

If you've got a boolean, why not have a function that takes a boolean, and not a byte?

This code works, I think; I'm out of town without an arduino to run it on, but the disassembly looks like it does the intended thing. I couldn't get #undef to work.

//#undef true  
//#undef false
const boolean True = 1;
const boolean False = 0;

void f(int x) {
  Serial.print("integer version");
}
void f(boolean x) {
  Serial.print("boolean version");
}
void setup(void){
 Serial.begin(9600); 
}

void loop (void){
   f(True);//boolean
   //comment line
   f(1);//integer
}

I, for one, think the definition of true and false should be changed.