Skip to content

Commit

Permalink
Make preprocessor conditional false when identifier undefined
Browse files Browse the repository at this point in the history
A preprocessor conditional directive intended to only evaluate as true when compiling for the Arduino Nano 33 BLE board
was also evaluating as true when compiling for any board that didn't define the compared identifiers because undefined
identifiers are replaced with 0 by the C/C++ preprocessor, making them equal.

From the C++11 standard section 16.1, paragraph 4:

> After all replacements due to macro expansion and the defined unary operator
have been performed, all remaining identifiers and keywords 148 , except for true and false, are replaced
with the pp-number 0

The fix is to modify the directive to check whether the macro has been defined.
  • Loading branch information
per1234 committed Dec 2, 2020
1 parent b64fe15 commit 8611588
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define DHT21 21 /**< DHT TYPE 21 */
#define AM2301 21 /**< AM2301 */

#if (TARGET_NAME == ARDUINO_NANO33BLE)
#if defined(TARGET_NAME) && (TARGET_NAME == ARDUINO_NANO33BLE)
#ifndef microsecondsToClockCycles
/*!
* As of 7 Sep 2020 the Arduino Nano 33 BLE boards do not have
Expand Down

0 comments on commit 8611588

Please sign in to comment.