Is there a way in Arduino Programming to list out all the Define in the code
when the library are loaded… at compile time
it will say if define, but i want to know what is define in my code for debugging?
Is there a way in Arduino Programming to list out all the Define in the code
when the library are loaded… at compile time
it will say if define, but i want to know what is define in my code for debugging?
Take a look at this option in the gcc preprocessor:
https://man.archlinux.org/man/extra/avr-gcc/avr-cpp.1.en
-dletters
Says to make debugging dumps during compilation as specified by letters. The flags documented here are those relevant to the preprocessor. Other letters are interpreted by the compiler proper, or reserved for future versions of GCC, and so are silently ignored. If you specify letters whose behavior conflicts, the result is undefined.
-dM
Instead of the normal output, generate a list of #define directives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no file foo.h, the command
touch foo.h; cpp -dM foo.h
shows all the predefined macros.
Note that there are a LOT of #defines that are done for you that you probably didn't use. An Uno "blink.ino" compile with -E -dM
produces some 2400 lines of output.
I think the OP means the "#if defined" statements
This test sketch shows how I use them. With the code like this, it will call all the print statements. If you comment out the "// #define DEBUG", you only get the normal stuff.`
#define DEBUG
void setup() {
Serial.begin(9600);
#if defined(DEBUG)
Serial.print("DEBUG");
#endif
}
void loop() {
Serial.println("Normal");
#if defined(DEBUG)
Serial.println("Debug stuff");
#endif
delay(500);
}
i think there are problems... lets say if define ESP32 may be different than ESP_dev_board... whatnot causes compile problems that are impossable to chase down
To the compiler, these are indistinguishable from any other #define.
Optiboot uses some "clever" code to put what it considers important options into a section of memory (if there is enough memory.) Theoretically this enables one to look at the binary and see which compile options were defined (which COULD be really useful.)
Something similar could be added to most programs, perhaps in a way where the option info is created and is visible if you look carfully, but optimized away (as not referenced) in the final binary...