Skip to content

Commit ece02e9

Browse files
Instead of #defining true and false, include stdbool.h
In C++, true and false are language keywords, so there is no need to define them as macros. Including stdbool.h in C++ effectively changes nothing. In C, true, false and also the bool type are not available, but including stdbool.h will make them available. Using stdbool.h means that we get true, false and the bool type in whatever way the compiler thinks is best, which seems like a good idea to me. This also fixes the following compiler warnings if a .c file includes both stdbool.h and Arduino.h: warning: "true" redefined [enabled by default] #define true 0x1 warning: "false" redefined [enabled by default] #define false 0x0 This fixes #1570 and helps toward fixing #1728. This only changed the AVR core, the SAM core already doesn't define true and false (but doesn't include stdbool.h either).
1 parent 3035239 commit ece02e9

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

Diff for: hardware/arduino/avr/cores/arduino/Arduino.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#define Arduino_h
2222

2323
#include <stdlib.h>
24+
#include <stdbool.h>
2425
#include <string.h>
2526
#include <math.h>
2627

@@ -43,9 +44,6 @@ void yield(void);
4344
#define OUTPUT 0x1
4445
#define INPUT_PULLUP 0x2
4546

46-
#define true 0x1
47-
#define false 0x0
48-
4947
#define PI 3.1415926535897932384626433832795
5048
#define HALF_PI 1.5707963267948966192313216916398
5149
#define TWO_PI 6.283185307179586476925286766559

0 commit comments

Comments
 (0)