Booleans

Hi,

I'm currently writing a library and I need to use booleans.

When programming in C++ I usually use "bool" and not "boolean". Is there any difference ? Which one should I use ?

Thanks.

Pollop.

You can use either. I don't think there is a difference, other than boolean is the keywords file that the IDE uses to hilight words.

Hi, in C++ "bool" is a built-in data type that can have values "true" or "false". In any case in C and C++ language the test conditions are considered FALSE when the result is zero and TRUE if not ( if(2) { printf("true\n"); } is a correct statement.) In Arduino.h you can find the following type definition:

typedef uint8_t boolean;

so the boolean type is defined in the arduino environment as a byte. Note that the C++ standard does not specify what is the size of a bool type, it is implementation dependent. Usually in microcontroller programming, because of the limited resources and 'low level' applications that normally are required, it's important to know how the variables are represented in memory. From the boolean typedef you see immediately that it will be stored in 8 bits as an unsigned byte. Also the byte type is defined in arduino.h as a uint8_t. I suggest to use the types defined in the arduino environment.

That's true, but I don't know if the IDE pre-processor does anything to convert it to a bool.