Surprise!

Perhaps not to you, but this one caught me underwears:

I failed to check the type of variable I had in front of me and thought that incrementing it would toggle the bottom bit. Sooner or later (OK, a lot later) I did check, it was boolean which is Ard-speak for bool (why?!). Changing it to unsigned char with which I am more familiar changed fixed it!

My friend google helped me out

"Incrementing an object with bool type results in its value been [sic] set to true."

but there's no replacing the hair I tore out.

This will happen to me again. May it never happen on you.

a7

Are you saying that you knew it was wrong to increment a bool but thought it would be OK to increment a boolean ?

Incidentally Arduino-speak for unsigned char is byte.

...R

this one caught me underwears

How interesting!

Robin2:
Are you saying that you knew it was wrong to increment a bool but thought it would be OK to increment a boolean ?

No.

Robin2:

Incidentally Arduino-speak for unsigned char is byte.

...R

Yeah, Ard-speak. lol. Sticking with unsigned chars, they just work better. :wink:

a7

alto777:
Sticking with unsigned chars, they just work better. :wink:

I suspect there is absolutely no difference in the technical performance.

...R

alto777:
it was boolean which is Ard-speak for bool (why?!)

The Arduino IDE is based on the Processing IDE. I think the original idea was to make something that would provide the same beginner-friendly experience programming microcontrollers as Processing does on computers. The two projects would be somewhat complementary. For this reason, you'll notice a lot of similarities between the Arduino standard API and the Processing language. Processing language is based on Java, which uses the boolean type (byte too). Years later, I think only a small percentage of Arduino users also use Processing so there is not such an advantage. In the case of boolean vs bool, I think the disadvantages of using a non-standard type alias far outweigh the minor benefits. For this reason, I undertook a project to encourage the use of bool instead of boolean.

In the case of byte vs unsigned char, I do think the advantages of a more beginner friendly type name outweigh the disadvantages. "unsigned char" just doesn't make intuitive sense like byte does.

A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.) (Arduino Reference)
So what happens in the following snippet ?

bool thebool=true;
while (thebool) {
  thebool++;
  Serial.print('.');
  }
Serial.println('*');

Deva_Rishi:
A bool holds one of two values, true or false. (Each bool variable occupies one byte of memory.) (Arduino Reference)
So what happens in the following snippet ?

bool thebool=true;

while (thebool) {
  thebool++;
  Serial.print('.');
  }
Serial.println('*');

Just a long line of dots. It never wraps back to zero.