#if TEST == pollo
Serial.println("TEST is pollo"); #else
Serial.println("TEST is not pollo"); #endif
}
void loop()
{
}
You can assign to TEST any value but the outut is always "TEST is pollo". Why? Can anyone help me?
I am using ESP32 library 1.0.6 and Arduino 1.8.16 (windows store 1.8.51.0).
The Arduino forum is generally for MCU boards and software manufactured and distributed by Arduino.
Other manufacturers and volunteers have modified the Arduino IDE to work with their compilers and linkers, and nothing is guaranteed to work as it does (well, if it does) with Arduino boards. You might try the ESP32 forum.
Meh. Even though they have the same name, the Arduino project is much bigger than the Arduino company. All things related to the Arduino project are welcome here. And in the case of the ESP32, many of the official boards actually have an ESP32 microcontroller in their WiFi modem.
But this question is not even specific to any one microcontroller. This is about C++.
From § 16.1 ¶4 of the C++11 standard:
After all replacements due to macro expansion and the defined unary operator
have been performed, all remaining identifiers and keywords, except for true and false, are replaced with the pp-number 0
So what that means is your conditional is equivalent to this:
Wow- make a newcomer feel unwelcome, why don't you?
This is the first time Connetsrl has posted — let’s welcome them to our community!
There is absolutely NOTHING in Connestri's question that is restricted to Arduino boards only that rates this kind of dismissal. Preprocessor statements in the Arduino IDE work the same whether it's an Arduino board or an ESP board.
You don’t have to load the sketch onto the Arduino to test the behavior of the preprocessor #if directive. The #warning directive will display a message at compile time (gcc compiler )
#if TEST == pollo
#warning "TEST is pollo"
#else
#warning "TEST is not pollo"
#endif
If you WANT to have symbol definitions for your #defines, you can "cheat" by pre-defining all of your symbolic names with unique numeric values, off in some .h file. Such as:
//main.c
#include "testnames.h"
#define TEST pillo
:
#if TEST == pillo
// stuff.
#elif TEST == pollo
// other stuff
#else
#error undefined test
#endif
the current Optiboot source code uses this extensively to allow compile time naming of chip pins like avr-gcc optiboot.c -DLED=B5 -DUARTRX=D0 and similar. It's "ugly" in the implementation (10 ports with ~8 bits each makes for #elif chains 500+ lines long!), but it's not difficult to implement (a good editor with macro capabilities helps a lot), and it makes things much easier for the "user."